I need a regex to match both, integer values aswell as float numbers (whereas float numbers have a "." as seperator). Those numbers are always in a bracket and may have a leading "+".
What should be valid:
What should be invalid:
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
(? i) makes the regex case insensitive. (? c) makes the regex case sensitive.
[0-9]+|[0-9]+). This regular expression matches an optional sign, that is either followed by zero or more digits followed by a dot and one or more digits (a floating point number with optional integer part), or that is followed by one or more digits (an integer).
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
This should work on most perl like regex engines:
/(\d+(?:\.\d+)?)/
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