Regular expression containing all specific letters in Notepad ++

I have a list of dictionaries in the form of text files and you want to select specific words containing all the elements of the list of specific characters. Use the notepad ++ text editor to apply the following regular expression in the dictionary list. I tried the following regex operator in notepad ++;

[BLT]+ 

However, this does not correspond to all the letters in square brackets, but any of the letters in square brackets. Then I also tried the following regular expression, including word boundary;

 \b[BLT]+ 

And this expression again coincides with all occurrences of words, including any , but not all letters listed between square brackets.

Desired behavior

Say the dictionary contains a list as shown below:

 AL BAL BAK LABAT TAL LAT BALAT LA AB LATAB TAB 

I need an expression containing all the letters "B", "L", "T" (not any!), So the expected behavior should be as follows:

 LABAT BALAT LATAB 

What is a minimalistic and general regex for this problem?

+5
source share
1 answer

You can use lookaheads :

 ^(?=.*B)(?=.*L)(?=.*T).+$ 

As an example for a more general case, the optimized regular expression for at least 1 B , 2 L and 3 T s:

 ^(?=[^B\n]*B)(?=(?:[^L\n]*L){2})(?=(?:[^T\n]*T){3}).+$ 
+5
source

Source: https://habr.com/ru/post/1236427/


All Articles