For instance,
.23 and 0.23 matches
12. and 12.23 matches
12.asd23 will get the 12. part
asd.23 does not match
12.23.23 will get the 12.23 part
etc, etc ...
Now that I said that, here it goes:
PHP example to get the part of the string matched by the regex (using preg_match):
if (preg_match('/^(?:[\d]+|)(?:\.{1}(?:\d+)?)?/', $subject, $regs)) {
$result = $regs[0];
} else {
$result = false;
}
Javascript example:
result = subject.match(/^(?:[\d]+|)(?:\.{1}(?:\d+)?)?/g);
No comments:
Post a Comment