我正在寻找我想在我的 php 名称生成器脚本中使用的正则表达式模式。
它应该检测字符串是否包含三个连续的辅音。 但如果三个连续辅音中的两个连续辅音相同,则不应检测字符串。
例子:
"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.
请帮我找到这样的正则表达式模式。
最佳答案
(([b-df-hj-np-tv-z])(?!\2)){3}
http://gskinner.com/RegExr/?2vtnt
编辑
这种模式有一个极端情况,如果它以相同的最后一个辅音开头,它就会失败。
例如 xyz
应该匹配 xyz
但不匹配。
这将是一个更准确的模式。
(([b-df-hj-np-tv-z])(?!\2)){2}[b-df-hj-np-tv-z]
关于php - 多个辅音的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9143105/