如何编写至少包含一个字母但第一个字符不能是数字的正则表达式?我想这匹配包含字母的字符串,其中第一个字符不是数字
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) –