正则表达式用于匹配以数字结尾的字符串,例如:
尝试了这个方法,但它并没有起作用。
"c1234" - match
"c12" - match
"c" - no match
尝试了这个方法,但它并没有起作用。
(?|c(?|[0-9]*$))
再次感谢您,
起始字符串也需要具体说明。
"c1234" - match
"c12" - match
"c" - no match
(?|c(?|[0-9]*$))
再次感谢您,
起始字符串也需要具体说明。
只需使用
\d$
检查字符串是否以数字结尾
如果您希望您的字符串以字母"c"开头,后跟一些数字,请使用以下代码
c\d+$
d
后面的 +
。 - TiMESPLiNTER^c[0-9]+$
[\s\S]*\d$
if (preg_match('/[\s\S]*\d$/', $value)) {
#match
} else {
#no match
}
动态方式是:
import re
word_list = ["c1234", "c12" ,"c"]
for word in word_list:
m = re.search(r'.*\d+',word)
if m is not None:
print(m.group(),"-match")
else:
print(word[-1], "- nomatch")
结果:
c1234 -match
c12 -match
c - nomatch