0
什麼是正則表達式匹配字符串包含至少 3個散列用於分隔單詞?php正則表達式preg_match
匹配:
the-rain-in-spain
the-rain-in-spain-is-falling-on-the-plain
不匹配:
the-rain-in
the---in
什麼是正則表達式匹配字符串包含至少 3個散列用於分隔單詞?php正則表達式preg_match
匹配:
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
}
希望這有助於
你試過自己做點什麼嗎? – 2013-02-19 05:18:14