m/ ^ # anchor to the beginning of the string -? # 0 or 1 dashes (for negative numbers I assume) \.? # 0 or 1 decimal points \d+ # 1 or more numbers (?:\.\d+)? # 0 or 1 decimal places followed by a number $ # anchor to the end of the string /x
So basically what you have is a a possibly negative, possibly decimal number (-?\.\d+), followed by an optional decimal and number.
# some examples /^-?\.?\d+/ matches 123 or -123 or -.123 or .123 /^-?\.?\d+(?:\.\d_)?/ matches those and also 123.45 or -123.45 or -.123.45 (probably a bug!) or -123.23532 or .235235235235.235235235235235325
The (?:...) construct lets you use parentheses for grouping, without assigning them to the $n variables, so your regexp contains parens that keep the \. and \d+ together, but doesn't assign the match to $1.
| We're not surrounded, we're in a target-rich environment! |
|---|
In reply to Re: What does this regex do?
by jasonk
in thread What does this regex do?
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |