user3466687
user3466687

Reputation: 239

Regex to match a period

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.

Upvotes: 20

Views: 70289

Answers (1)

Brandon - Free Palestine
Brandon - Free Palestine

Reputation: 16656

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.

Upvotes: 32

Related Questions