I know about x (?! Y) - finds x only if x is not followed by y. But I need to exclude the word regardless of where it stands.

Find the letter A but exclude such words: watermelon, abandon, etc.

  • Is it necessary to solve the problem with one regular expression? Can't remove exception words from a string and then apply a regular expression? - cheops
  • add examples of input lines and what you want to see at the output - Grundy
  • @cheops is generally a regular for working with text in notepad ++, in the code I would implement everything myself, so you need one regular expression. - user208916
  • @Khipster, if this is for notepad++ why is the javascript label worth it? - Grundy
  • @Grundy and in notepad ++ the same regular expressions as in JavaScript, well, or I can write a script, of course, if there is no regular procedure. - user208916

2 answers 2

Regarding

Find the letter А but exclude such words: арбуз , абандон , etc.

In Notepad ++, use the exciting alternate mask and the conditional replacement pattern:

 (\b(?:арбуз|абандон)\w*)|а 

Replaced by

 (?1$1:я) 

Those. using (\b(?:арбуз|абандон)\w*)|а we find and save all the exclusion words (with or without endings with \w* ) in group 1, and if they match, they will be restored in the text using ?1$1 (if the first submask is found, restore it), and the letter а will be changed / deleted in all other cases ( ).

Regarding the use of the Match case parameter, decide for yourself.

enter image description here

  • Instead of \w you can use \p{L} to find only Unicode letters. - Wiktor Stribiżew

Check that the string does not contain the specified words:

 /^((?!арбуз|абандон).)*$/i 

Select all the letters а that are not included in the given words:

 s.match(/арбуз|абандон|а|$/gi).filter(m => m.length===1) 
  • you have another regular match in match - Grundy
  • @Grundy, I know. These are different regulars. What is not satisfied? - Qwertiy
  • I honestly do not quite understand what you are doing :) - Grundy
  • one
    @Qwertiy, why in the second regular expression the end of the string $? In the first, it is clear why, in the second - no. Can you describe and generally stop on the second line in more detail? - cheops
  • one
    @cheops, for $ he is guaranteed to find an empty string. Without it, on a string without letters would be null, which would .filter to .filter . And so we will definitely find something. - Qwertiy