Regex: find the number between parentheses

I need a regex that will find the highlight in bold below:

20 (LBDD hello 312312 ) Potato 1651 (98)

20 (LBDD hello 312312 rabbit) Potato 1651 (98)

20 ( 312312 ) Potato 1651 (98)

((\ d +)) find the number 98

I do not know what to do if there are other characters in parentheses

+7
source share
2 answers

This corresponds to only 312312 in the first capture group:

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

Regexplanation:

 ^ # 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 

See here .

+34
source

this is a regular expression

 @"\([^\d]*(\d+)[^\d]*\)" 

the brackets are the capturing group, and \( are the copied brackets that are the actual bracket in your input string.

as a note: depending on what language you will influence your regular expression in, you might need to avoid your escape char, \ , so be careful.

I would be careful with this, although one of the limitations for regular expression in the tutorial is that it cannot correctly identify the text in brackets.

+1
source

All Articles