php - 多个辅音的正则表达式

标签 php regex string logic

我正在寻找我想在我的 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/

相关文章:

当按下下一个按钮时,PHP 分页不会改变

c# - 正则表达式匹配问题

string - 为什么MFC中有这么多字符串类型?

c++ - 使用CStringW/CStringA和CT2W/CT2A转换字符串有什么区别?

php - 来自 html 的多个操作?

javascript - 计算所选复选框的总价

php - 查询限制被忽略

双倍的正则表达式

java - 正则表达式查找部分输入是否是有效的 JSON

java - 如何收集必须像字符串一样格式化的数字?