Hi!

At Sun, 12 Feb 2006 08:12:47 +0900, Jeppe J. wrote:

Will that expression include both integers and decimal numbers?

[-+]?([1-9]\d*(,[0-9]+)?)|(0(,[0-9]+)?)

has two parts:

[-+]?

([1-9]\d*(,[0-9]+)?)|(0(,[0-9]+)?)

The first one is an optional sign. The second one is an alternative

between to two cases:

[1-9]\d*(,[0-9]+)?

0(,[0-9]+)?

Let’s first consider the first case

[1-9]\d*(,[0-9]+)?

It has two parts, namely

[1-9]\d*

(,[0-9])?

The first part by itself covers all integers larger than zero. The

overall expression additionally covers all floating point numbers

larger than 1.

Now the second case

0(,[0-9]+)?

This one covers zero and all decimal numbers larger than 0 and smaller

than 1.

The regex I provided intentionally supports none of

[±],\d+

[±]0+\d+

You may as well use the shorter version

[-+]?(([1-9]\d*(,\d+)?)|(0(,\d+)?))

Wait a moment, I am not sure if that is correct. To be on the safe

side I’d rather use one of these where anything that follows the

optional sign has been put into another pair of parentheses:

[-+]?(([1-9]\d*(,[0-9]+)?)|(0(,[0-9]+)?))

[-+]?((([1-9]\d*(,\d+)?)|(0(,\d+)?)))

I am one of those guys who sometime run out of placeholders when doing

search and replace in vim (which has nine of them).

Josef ‘Jupp’ Schugt