0 after setting and successfully
parsing the regular expression pattern.
The new pattern will be used to
match strings specified with methods
match or
pos.
Returns an error code otherwise.
MAXIMAL, or to
“lazy” by specifying option MINIMAL.
The default is to use the current matching type.
patterns = "A [:alpha:]{4} fl?*.", -
"?*[l|e]?*e?*[r|g]?*", -
"[invalid"
texts = "A nice flower.", -
"A yellow flower.", -
"A blue flag."
re = .RegularExpression~new
do pattern over patterns
code = re~parse(pattern)
if code == 0 then
do text over texts
say text~left(16) -
re~match(text)~?("matches", "doesn't match") "regex" pattern
end
else
say "error" code "parsing pattern" pattern
say
end
::requires rxregexp.cls
A nice flower. matches regex A [:alpha:]{4} fl?*.
A yellow flower. doesn't match regex A [:alpha:]{4} fl?*.
A blue flag. matches regex A [:alpha:]{4} fl?*.
A nice flower. matches regex ?*[l|e]?*e?*[r|g]?*
A yellow flower. matches regex ?*[l|e]?*e?*[r|g]?*
A blue flag. matches regex ?*[l|e]?*e?*[r|g]?*
error 3 parsing pattern [invalid
nrs = 1, 42, 0, 5436412, "1A", "f43g"
re = .RegularExpression~new("[1-9][0-9]*")
do nr over nrs
say nr "is" re~match(nr)~?("a valid", "an invalid") "number"
end
say
-- allow hexadecimal numbers and a single 0
re~parse("0|([1-9a-fA-F][:xdigit:]*)")
do nr over nrs
say nr "is" re~match(nr)~?("a valid", "an invalid") "number"
end
::requires rxregexp.cls
1 is a valid number
42 is a valid number
0 is an invalid number
5436412 is a valid number
1A is an invalid number
f43g is an invalid number
1 is a valid number
42 is a valid number
0 is a valid number
5436412 is a valid number
1A is a valid number
f43g is an invalid number