![](/img/trans.png)
[英]JavaScript Unicode Regex - Range out of order in character class
[英]“range out of order in character class” in PHP regex?
我試圖讓這項工作有一段時間,但徒勞無功。 我想創建一個 php 正則表達式來檢查一個字符串是否至少有一個數字和至少一個符號( _-+=*& )
這是我的正則表達式
$result = preg_match('/^(?=.*\d)(?=.*[_-+=*&]).{3,}$/',$pass);
我收到以下錯誤警告:preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 17 in myfile.php on line 8
有什么幫助嗎?
-
需要轉義,或者放在[...]
列表的開頭/結尾:
$result = preg_match('/^(?=.*\d)(?=.*[-_+=*&]).{3,}$/',$pass);
如果不這樣做, -
被解釋為范圍運算符,如果[xy]
x > y
,則會出現該錯誤。
當我收到此警告時,我在模式末尾使用了/u
。 去嘗試一下。 這意味着Ungreedy 模式
$pattern = "^([ `anything` ])$/u";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.