Tom Gullen
Tom Gullen

Reputation: 61775

c# regexp match

I have the regexp:

\[IN\](\d+)\[/IN\]

Which works fine for:

...[IN]34[/IN]...
...[IN]1[/IN]...
...[IN]12[/IN]...
etc

But it doesn't quite work for decimals, IE:

...[IN]3.5[/IN]...
...[IN]2.8[/IN]...
...[IN]9.4[/IN]...
etc

How do I make it match these as well?

Thanks!

Upvotes: 1

Views: 204

Answers (4)

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47068

Something like this

[IN](\d+|\d+\.\d+)?[/IN]

This ensures that you have a number after the dot if you have a dot.

Upvotes: 0

red-X
red-X

Reputation: 5138

From the top of my head i think it should be this:

[IN](\d+\.?\d*)[/IN]

EDIT: tested and corrected version:

\[IN\](\d+(\.\d+)?)\[\/IN\]

Upvotes: 2

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55519

Try this -

\[IN\]\d+(\.\d+)?\[/IN\]

Upvotes: 2

Michał Niklas
Michał Niklas

Reputation: 54342

It doesn't check if it is valid float (have one decimal dot):

([\d.]+)

Upvotes: 2

Related Questions