I am trying to write a regex to get the numbers from strings like these ones:
我正在写一个regex来从这些字符串中获取数字:
javascript:ShowPage('6009',null,null,null,null,null,null,null)
javascript:BlockLink('2146',null,null,null)
I am having difficulty writing the regex to grab these numbers.
我很难编写regex来获取这些数字。
Could anyone lend a hand?
谁能帮忙吗?
Cheers
干杯
Eef
Eef
4 个解决方案
#1
22
Try this:
试试这个:
(\d+)
What language are you using to parse these strings? If you let me know I can help you with the code you would need to use this regular expression.
你用什么语言来解析这些字符串?如果您让我知道我可以帮助您处理需要使用这个正则表达式的代码。
#2
5
Assuming:
假设:
- you want to capture the digits
- 你想要捕捉这些数字
- there's only one set of digits per line
- 每行只有一组数字
Try this:
试试这个:
/(\d+)/
then $1
(Perl) or $matches[1]
(PHP) or whatever your poison of choice is, should contain the digits.
然后$1 (Perl)或$matches[1] (PHP)或任何您喜欢的东西都应该包含这些数字。
#3
2
integer or float:
整数或浮点数:
/\d+((.|,)\d+)?/
#4
0
just match numbers: \d+
只匹配数字:\ d +
#1
22
Try this:
试试这个:
(\d+)
What language are you using to parse these strings? If you let me know I can help you with the code you would need to use this regular expression.
你用什么语言来解析这些字符串?如果您让我知道我可以帮助您处理需要使用这个正则表达式的代码。
#2
5
Assuming:
假设:
- you want to capture the digits
- 你想要捕捉这些数字
- there's only one set of digits per line
- 每行只有一组数字
Try this:
试试这个:
/(\d+)/
then $1
(Perl) or $matches[1]
(PHP) or whatever your poison of choice is, should contain the digits.
然后$1 (Perl)或$matches[1] (PHP)或任何您喜欢的东西都应该包含这些数字。
#3
2
integer or float:
整数或浮点数:
/\d+((.|,)\d+)?/
#4
0
just match numbers: \d+
只匹配数字:\ d +