[英]php regex preg_match
匹配包含至少 3个用于分隔单词的哈希的字符串的正则表达式是什么?
火柴:
the-rain-in-spain
the-rain-in-spain-is-falling-on-the-plain
不匹配:
the-rain-in
the---in
您可以使用此正则表达式
\w+(-\w+){3,}
\\w
类似于[a-zA-Z0-9_]
\\w+
匹配1到多个字符
{3,}
是一个将前面的第3组匹配多次的量词
我不了解php,但这对我有用
//string strtmp = "the-rain-in";
//string strtmp = "the-rain-in-spain";
string strtmp = "the-rain-in-spain-is-falling-on-the-plain";
//string strtmp = "the---in";
Match matchdec = Regex.Match(strtmp, @"\w+(-\w+){3,}", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
if (matchdec.Success)
{
//your code
}
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.