Skip to content
Advertisement

How to match any combination of letters using regex?

How can I match letters a,b,c once in any combination and varying length like this:

The expression should match these cases:

abc
bc
a
b
bca

but should not match these ones:

abz
aab
cc
x

Advertisement

Answer

Use regex pattern

b(?!w*(w)w*1)[abc]+b

You can use this pattern with any set and size, just replace [abc] with desired set…


Example:

enter image description here

(above output is from myregextester)

Advertisement