![](/img/trans.png)
[英]PCRE REGEX to match one or more sentences containing a set of characters
[英]regex to match entire words containing (one or more) mandatory and allowed characters
我想匹配包含至少一個必填字符和允許的字符的整個單詞。
例如
強制字符為:[t,a,x]
允許的字符為:[i,e]
t : passed (one of mandatories are here)
tea : passed (two of mandatories(t,a) and one allowed(e) here)
e : failed (none of mandatory is here)
teas : failed (two of mandatories(t,a) and one allowed(e) here but one intruder(s))
合適的REGEX代碼是什么? 它將用於搜索12.000行的MySQL表,其中每行一個單詞作為一個PHP項目。
除了給您一個直接的答案外,讓我幫您自助。 通過的單詞由以下序列組成:
為每一個都編寫正則表達式,然后將它們連接起來就可以得到整個事情的正則表達式。
在perl中會..
$string =~ /^[tax]*[ie]+$/i; #i is for ignore case
*是1或更大+是0或更大
我只是意識到您想保留所有單詞,讓我重寫它。
^和$將匹配行的開始和結束。
您可以使用以下模式:
\b[ie]*+[taxie]++\b
說明:
由於[ie]*+
在左側具有單詞邊界和所有格量詞,因此它會盡可能抓住所有i
和e
,並且永遠不會將其退還,因此下一個字符必須是下一個字符t
, a
或x
帶有至少包含1個字符的+量詞的類。
右側的單詞邊界禁止使用其他類型的字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.