Christof
Christof

Reputation: 3927

Replace everything but number and >actual< decimal points

I'm trying to get a regex working that will replace everything except for numbers and a decimal point (easy). The tricky part: the decimal point is optional but, if present, must be trailed by a further number.

So:

.10 => 10
10. => 10
10.- => 10
1.0 => 1.0

I'm not quite sure how to define the "except numbers followed by an optional decimal point but mandatory number after the optional decimal point" bit :)

Thanks!

Upvotes: 1

Views: 1513

Answers (1)

UncleZeiv
UncleZeiv

Reputation: 18488

It would be something like this:

\d+(\.\d+)?

(Please note that the regex syntax you are using may require different escaping.)

Upvotes: 2

Related Questions