如何編寫至少包含一個字母但第一個字符不能是數字的正則表達式?我想這匹配包含字母的字符串,其中第一個字符不是數字
str = "a"
str =~ /^[^\d][[:space:]]*[a-z]*/i
# => 0
str = "="
str =~ /^[^\d][[:space:]]*[a-z]*/i
# => 0
的"=" is matched even though it contains no letters. I expect the
「一」 to match, and similarly a string like
「3abcde」`應該不匹配。
' [az] *'和'[[:space:]] *'可以匹配空字符串,'='不是數字,匹配w ith'[^ \ d]'。試試'/ \ A(?!\ d)。* [a-zA-Z]。* \ z/m'甚至是'/\A(?!\d).*\p{L}.*\z/m' –
另一種方式是'str [0]!〜/ \ d/&& str =〜/ [[:alpha] /#=> 4'(truthy) –