2 回答

TA貢獻1847條經驗 獲得超11個贊
^[\x00-\x7F]+$
- 匹配完全由 ASCII 字符組成的字符串。
[^{}$]*
?匹配零個或多個不同于{
,}
和 的字符$
。
因此,第二條規則匹配任何字符串。如果這是您的意圖,只需使用第一個正則表達式。
如果您想匹配任何純 ASCII 字符串(不包括 ){
,}
并$
使用
^(?=[\x00-\x7F]+$)[^{}$]*$
解釋
--------------------------------------------------------------------------------
? ^? ? ? ? ? ? ? ? ? ? ? ? the beginning of the string
--------------------------------------------------------------------------------
? (?=? ? ? ? ? ? ? ? ? ? ? look ahead to see if there is:
--------------------------------------------------------------------------------
? ? [\x00-\x7F]+? ? ? ? ? ? ?any character of: '\x00' to '\x7F' (1 or
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?more times (matching the most amount
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?possible))
--------------------------------------------------------------------------------
? ? $? ? ? ? ? ? ? ? ? ? ? ? before an optional \n, and the end of
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?the string
--------------------------------------------------------------------------------
? )? ? ? ? ? ? ? ? ? ? ? ? end of look-ahead
--------------------------------------------------------------------------------
? [^{}$]*? ? ? ? ? ? ? ? ? any character except: '{', '}', '$' (0 or
? ? ? ? ? ? ? ? ? ? ? ? ? ?more times (matching the most amount
? ? ? ? ? ? ? ? ? ? ? ? ? ?possible))
--------------------------------------------------------------------------------
? $? ? ? ? ? ? ? ? ? ? ? ? before an optional \n, and the end of the
? ? ? ? ? ? ? ? ? ? ? ? ? ?string
添加回答
舉報