Find multiple words on one line using Notepad ++

Below is my function to find a two-word combination in VS or Notepad ++.

Find: Word1 +[ \w\S]*(?= Word2 )

Problem - Change the word order for the search.

For example:

( function ( a, b, c, myVars ) {})() search text

function +[ \w\S]*(?= myVars ) .

myVars +[ \w\S]*(?= function ) will not be found.

Need: Word1 <---> Word2

I will be glad to see the answer.

Additional examples:

html separated lines of a file: find: (<), replace: \ n $ 0

html join tag with name : find: \ n </ name > replace: </ name >

wrap in tag : find: ^ ([\ w \ S] +) replace: < tag > \ 1 </ tag >

HTML Character Codes < - & # x3c; and > - & # x3e;

0
editor regex text line
Jun 08 '14 at 23:44
source share
1 answer

I do not use Notepad ++ , I use UltraEdit , and therefore the regular expression below was tested only using the Perl UltraEdit regular expression engine.

 \<(word1|word2)\>(?:[\t \S](?!\<\1\>))*?\<(?:word1|word2)\> 

This regular expression first searches for either word1 OR word2 , which should be found as a complete word, and not as a substring inside a word, since \< means the beginning of the word, and \> means the end of the word. It is also possible to use \b (word boundary) instead of \< and \> .

If one of the two words is found in a string, it searches for the next for 0 or more characters, which are either a space character or any non-primary character that is not greedy. It is also possible to use . instead of the character class [\t \S] , if the default matching behavior for a point is any character except string terminators, which is true for UltraEdit to limit the search by string.

On each character of this line, a negative lookahead is applied between the two words, checking whether the following characters after the already matching character match the word found by the first OR expression. This additional condition avoids searching for strings containing only one of two words in an OR expression twice.

The last OR expression from the beginning is added a second time to the expression, but this time as a group without marking. Therefore, the search must match another word from the OR expression in order to return a positive result.

0
Jun 13 '14 at 5:59
source share



All Articles