有人可以帮我构建这个正则表达式吗...
鉴于以下字符串......
我需要一个正则表达式,它将从文本中提取两个数字.月份名称会有所不同.括号,"小部件少"和"链轮"文本不会在字符串之间发生变化,但是如果这个文本也可以变化,那将非常有用.
提前致谢.
Sea*_*ard 37
如果你肯定知道只有2个地方你的字符串中有一个数字列表,这是你唯一要拿出的东西那么你应该可以简单地使用
\d+
Run Code Online (Sandbox Code Playgroud)
Tim*_*ker 27
^\s*(\w+)\s*\(\s*(\d+)\D+(\d+)\D+\)\s*$
Run Code Online (Sandbox Code Playgroud)
应该管用.匹配后,反向引用1将包含月份,反向引用2将包含第一个数字,反向引用3将包含第二个数字.
说明:
^ # start of string
\s* # optional whitespace
(\w+) # one or more alphanumeric characters, capture the match
\s* # optional whitespace
\( # a (
\s* # optional whitespace
(\d+) # a number, capture the match
\D+ # one or more non-digits
(\d+) # a number, capture the match
\D+ # one or more non-digits
\) # a )
\s* # optional whitespace
$ # end of string
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
65948 次 |
最近记录: |