KW.pm
Regular Expressions
#8
Quantifiers
Quantifiers appear after an atom to specify how many times that atom should appear consecutively in a match
*
will match 0 or more times.
/a*/
will match a string with any number of 'a's in it, even none! "bad", "cabaal", and "bcdefg" all match
+
will match 1 or more times.
?
will match once or match nothing. (It may or may not be there.)
{#}
or
{#,#}
will match exactly # times, or a range from # to # times
When used in combination with
()
and metasymbols you can do more useful things:
/\d{,2}(,\d{3})*/
matches a number with comma separators: "1", "2,300", "46,012,962" all match
<< Previous
|
Index
|
Next >>
Copyright © 2002
Christopher Calzonetti