Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match a period

Tags:

regex

matching

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.
like image 204
user3466687 Avatar asked Apr 09 '14 01:04

user3466687


People also ask

Is period a special character in regex?

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.

How do I search for a dot in regex?

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.

How do you escape a period in regex?

(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 \.

What does '$' mean in regex?

$ 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.


1 Answers

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.

like image 81
Brandon Wamboldt Avatar answered Oct 10 '22 06:10

Brandon Wamboldt