需要一个简单的RegEx才能在一个单词中找到一个数字

Pur*_*ome 4 regex

我有以下网址路由,我想确保路由的一部分只接受数字.因此,我可以提供一些检查单词的正则表达式.

/页/ {}当前页

所以..有人可以给我一个正则表达式,当该单词是一个大于0的数字(任意int)时匹配(即1 < - > int.max).

eye*_*ess 26

/^[1-9][0-9]*$/
Run Code Online (Sandbox Code Playgroud)

其他答案的问题:

/([1-9][0-9]*)/ // Will match -1 and foo1bar
#[1-9]+# // Will not match 10, same problems as the first
[1-9] // Will only match one digit, same problems as first
Run Code Online (Sandbox Code Playgroud)


Jer*_*ten 5

如果您希望它大于0,请使用此正则表达式:

/([1-9][0-9]*)/
Run Code Online (Sandbox Code Playgroud)

只要数字没有前导零(如'03'),这就可以工作.

但是,我建议只使用一个简单的[0-9]+正则表达式,并验证您的实际站点代码中的数字.