我尝试找到一个正则表达式匹配字符串只有当字符串不以至少三个’0’或更多结尾.直觉地,我试过:
.*[^0]{3,}$
但是当字符串的末尾有一个或两个零时,这不匹配.
如果你必须这样做没有lookbehind断言(即在JavaScript中):
^(?:.{0,2}|.*(?!000).{3})$
否则,使用hsz的答案.
说明:
^ # Start of string (?: # Either match... .{0,2} # a string of up to two characters | # or .* # any string (?!000) # (unless followed by three zeroes) .{3} # followed by three characters ) # End of alternation $ # End of string