I am trying to figure out a regular expression that matches a . (period). I looked for a formula but there was no formula that matches period.
12903,03930.
The \ before each period “escapes” the period—that is, it indicates that the period isn't a regex special character itself. In Example 1, no characters follow the last period, so the regex matches any IP address beginning with 192.168.
in regex is a metacharacter, it is used to match any character. To match a literal dot in a raw Python string ( r"" or r'' ), you need to escape it, so r"\." Unless the regular expression is stored inside a regular python string, in which case you need to use a double \ ( \\ ) instead.
(dot) metacharacter, and can match any single character (letter, digit, whitespace, everything). You may notice that this actually overrides the matching of the period character, so in order to specifically match a period, you need to escape the dot by using a slash \.
$ 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.
You just need to escape the . as it's normally a meta character. The escape character is a backslash:
\.
E.g:
/[0-9]+\./
Will match a number followed by a period.
If you wanted to match the entire number except the period, you could do this:
/([0-9,]+)/
Here we use the range operator to select all numbers or a comma, 1 or more times.
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