I have a dictionary list as a text files and want to select certain words that contains all of the members of a list of specific characters. Using the text editor notepad++ to apply following regular expression on the dictionary list. I've tried the following regular expression statement on notepad++;
[BLT]+
However, this matches not all of the letters in the square brackets, but any of the letters in the square brackets. Then I've also tried the following regular expression, including the word boundary;
\b[BLT]+
And this expression, again, matches all the occurences of the words including any, but not all of the letters listed in between the square brackets.
Let say, the dictionary contains a list as below;
AL
BAL
BAK
LABAT
TAL
LAT
BALAT
LA
AB
LATAB
TAB
What I need is an expression that contains all of the the letters 'B','L','T' (not any!), thus expected behaviour should be as below;
LABAT
BALAT
LATAB
What is the most minimalist and generic regular expression for this problem?
You can use lookaheads:
^(?=.*B)(?=.*L)(?=.*T).+$
As an example for a more general case, the optimized regex for at least 1 B
, 2 L
s and 3 T
s:
^(?=[^B\n]*B)(?=(?:[^L\n]*L){2})(?=(?:[^T\n]*T){3}).+$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With