簡體   English   中英

PHP正則表達式中的“字符類中的范圍亂序”?

[英]“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM