I need a regex who find the number in bold below :
20 (L.B.D.D. hello 312312) Potato 1651 (98)
20 (L.B.D.D. hello 312312 bunny ) Potato 1651 (98)
20 (312312) Potato 1651 (98)
((\d+)) find the number 98
I do not know what to do when there are other characters in the parenthesis
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
By placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regex. Only parentheses can be used for grouping.
The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.
Python Regex Escape Parentheses () You can get rid of the special meaning of parentheses by using the backslash prefix: \( and \) . This way, you can match the parentheses characters in a given string.
This only matches 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 it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With