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

问题描述

我需要一个能找到下面粗体数字的正则表达式:

I need a regex who find the number in bold below :

20 (L.B.D.D. 你好 312312) Potato 1651 (98)

20 (L.B.D.D. hello 312312) Potato 1651 (98)

20 (L.B.D.D. hello 312312 bunny ) Potato 1651 (98)

20 (L.B.D.D. hello 312312 bunny ) Potato 1651 (98)

20 (312312) 马铃薯 1651 (98)

20 (312312) Potato 1651 (98)

((\d+)) 找到数字 98

((\d+)) find the number 98

括号里有其他字符的时候不知道怎么办

I do not know what to do when there are other characters in the parenthesis

推荐答案

这只匹配第一个捕获组中的 312312:

This only matches 312312 in the first capture group:

^.*?\([^\d]*(\d+)[^\d]*\).*$

正则说明:

^        # Match the start of the line
.*?      # Non-greedy match anything
\(       # Upto the first opening bracket (escaped)
[^\d]*   # Match anything not a digit (zero or more)
(\d+)    # Match a digit string (one or more)
[^\d]*   # Match anything not a digit (zero or more)
\)       # Match closing bracket
.*       # Match the rest of the line
$        # Match the end of the line

此处查看.

这篇关于正则表达式:在括号之间找到一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 10:19