You must select all the words containing the word reg with any number of letters and numbers in front, except those that are limited to a slash. For example, to fit:

Amreg 1reg reg 

But so as not to come

 /Amreg /reg /1reg 

Help me please(

  • something like [^\/]*reg ? - Pavel
  • I already tried it. Such a regular season simply does not take into account the slash. That is, Amreg will only get out of / Amreg. And you need to / Amreg did not fit at all - Mikhail Chekavy February
  • and if so: ^[^\/]*reg ? - Pavel
  • /\b(?<!\/)\w*reg/ ? /\b(?<!\/)\w*reg\w*/ ? /\b(?<!\/)\w*reg\w*/u ? - Wiktor Stribiżew
  • 2
    @Mikhail Chekavy for the future, please indicate for which language or editor a regular course is needed. - UModeL

2 answers 2

 var txt = ` Amreg /1reg 1reg /reg /Amreg reg `; console.log(txt.match(/^([^/\s]*?reg)$/gm)); 

/^([^/\s]*?reg)$/gm

  • ^ - from the beginning of the line;
  • [^/\s] - any character except slashes, spaces, tabs and line breaks;
  • *?reg - match to the nearest reg ;
  • () - match capture;
  • $ - end of line.

Flags: g - full text search, m - multiline text.

  • And it seems that the question does not say that the words are one per line ... - Qwertiy
  • @Qwertiy in the question a lot of things are not said (zhezh partisans))), but an example of the data is given, and there are hyphenation. - UModeL

If the syntax allows, you can use the preview back:

 \b(?!/)\w*reg\w* 

If not, you can do so.

 [^/](\w*reg\w*) 

and take the first group.

  • Here I am about the same - if it allows :) - UModeL
  • @UModeL, added. - Qwertiy pm