1

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!

1
  • Can there also be exponents (1.4E-3)? Commented Nov 10, 2010 at 11:38

4 Answers 4

2

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\]
Sign up to request clarification or add additional context in comments.

Comments

2

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

([\d.]+)

Comments

2

Try this -

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

Comments

0

Something like this

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.