Ex: I want to ensure that a string must contain A, B, C, D
test strings:
"ABCDF" will be true
"AACDF" will be false (it not contains 'B')
"AABCDFG" will be true (it allows duplicated words)
Thanks to everyone!
Ex: I want to ensure that a string must contain A, B, C, D
test strings:
"ABCDF" will be true
"AACDF" will be false (it not contains 'B')
"AABCDFG" will be true (it allows duplicated words)
Thanks to everyone!
If you want a regex matching a single word containing 4 particular letters (in some bigger text), you can use:
(?=\w*A)(?=\w*B)(?=\w*C)(?=\w*D)\w+
It contains 4 positive lookups.
Each of them looks for A
, B
, C
and D
, respectively,
after a number of word chars (possibly 0).
Then there is the actual matching part - a sequence of word chars.
You should use also g
(global) option, to match all such words.
Another possibility is that you want to verify the whole string (something like password criteria verification). Then the regex can be:
(?=.*A)(?=.*B)(?=.*C)(?=.*D).+
The differences are that:
g
option is not needed.