需要一个简单的正则表达式来查找单个单词中的数字 [英] Need a simple RegEx to find a number in a single word

查看:17
本文介绍了需要一个简单的正则表达式来查找单个单词中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've got the following url route and i'm wanting to make sure that a segment of the route will only accept numbers. as such, i can provide some regex which checks the word.

/page/{currentPage}

/page/{currentPage}

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

so.. can someone give me a regex which matches when the word is a number (any int) greater than 0 (ie. 1 <-> int.max).

推荐答案

/^[1-9][0-9]*$/

其他答案的问题:

/([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

这篇关于需要一个简单的正则表达式来查找单个单词中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆