我有一个字符串:
0012309test07
我希望找到第一个零和字母。
00 12309 测试 07
当然,我找到了/[^\d]/
,here's the sample的字母。
但你如何抓住第一个零?
答案 0 :(得分:4)
使用此正则表达式\b0+|[a-zA-Z]+
答案 1 :(得分:1)
使用此模式
(^(0*))|([a-zA-Z]+)
答案 2 :(得分:0)
"0012309test07".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["0012309test07", "00", "12309", "test", "07"]
"12309test07".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["12309test07", "", "12309", "test", "07"]
"test07".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["test07", "", "", "test", "07"]
"0test07".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["0test07", "0", "", "test", "07"]
"1test07".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["1test07", "", "1", "test", "07"]
"test".match(/^(0*)(\d*)([^\d]+)(\d*)$/)
输出:["test", "", "", "test", ""]