[英]how to search all words starts match with regular expression character in php?
[英]PHP-Regular expression to only match words in a string without a specific character
我有以下PHP正则表达式可匹配以字母'Z'开头的单词。
/^Z/
我如何才能扩展此正则表达式以仅匹配以“ Z”开头但没有“ h”字母的单词。
我的代码是
if(preg_match('/^Z/','Zoe, Zoey, Zoho, Zander, Zap',$matches)){
echo $matches[0];
}
How could I extend this regex to only match words starting with 'Z', but without a 'h' letter.
您可以使用:
'/^Z[^h\W]*\b/'
使用[^h]
对象匹配h之外的任何内容, \\W
排除非单词字符,以及\\b
单词边界。
^Z[^h\\W]+\\b
使用正则表达式模式\\bZ[a-gi-z]*\\b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.