Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match any word containing all specific letters?

Tags:

regex

I'm trying to put together a regex that matches any word containing all specified letters.

For example:

a,b

Aaron: not match
Abby: match
Barry: match
Bobb: not match
Alley: not match
Abel: match
Bella: match

any ideas?

like image 931
draft Avatar asked Jan 07 '23 15:01

draft


1 Answers

(?=\w*a)(?=\w*b)\w+

Check that there's an "a", and a "b", before you get to a space or non-word character. Then capture all the characters until the end of the word.

like image 62
ColBeseder Avatar answered Jan 29 '23 07:01

ColBeseder