Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression That Contains All Of The Specific Letters in Notepad++

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.

Desired Behaviour

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?

like image 569
Levent Divilioglu Avatar asked Nov 20 '15 12:11

Levent Divilioglu


1 Answers

You can use lookaheads:

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

As an example for a more general case, the optimized regex for at least 1 B, 2 Ls and 3 Ts:

^(?=[^B\n]*B)(?=(?:[^L\n]*L){2})(?=(?:[^T\n]*T){3}).+$
like image 74
Walter Tross Avatar answered Nov 14 '22 22:11

Walter Tross