I want to match whole words that contain certain letters/characters. For example the pattern would match all words that contain the letter l
and a
, such as car
, patrol
, left
, etc. but it wouldn't match words like boom
, turnover
, digit
, etc.
A pattern like this should work:
\b(?=\w*[al])\w+\b
This will match one or more 'word' characters (letters, digits, or underscores) only of it contains an a
or l
character. The \b
around it will match the boundary of that word (e.g. where the next character is a non-word character), so it will capture the entire word.
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