Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for multiple Consonants

I am looking for a regex pattern I want to use in my php name generator script.

It should detect if the string contains three consecutive consonants. But it should not detect the string if two consecutive consonants of the three consecutive consonants are the same.

Example:

"hello" -> False, because there aren't 3 consecutive consonants.
"matching" -> True, because there are 3 consecutive consonants.
"apple" -> False, although there are 3 consecutive consonants, because two consecutive of them are the same.

Please help me to find such a regex pattern.

like image 395
danijar Avatar asked Feb 22 '23 14:02

danijar


1 Answers

(([b-df-hj-np-tv-z])(?!\2)){3}

http://gskinner.com/RegExr/?2vtnt


Edit

There's an edge case with this pattern that it fails if it's proceeded by the same last consonant. E.g xyzz should match xyz but doesn't.

This would be a more accurate pattern. (([b-df-hj-np-tv-z])(?!\2)){2}[b-df-hj-np-tv-z]

like image 198
Sam Greenhalgh Avatar answered Mar 04 '23 04:03

Sam Greenhalgh