+-,-"CURRENT"--+
>>-parse(-Pattern-+--------------+-------------------------><
+-,-"MAXIMAL"--+
+-,-"MINIMAL"--+
Example 5.196. Class REGULAREXPRESSION - parse method
a.0 = "does not match regular expression"
a.1 = "matches regular expression"
b = .array~of("This is a nice flower.",
"This is a yellow flower.", ,
"This is a blue flower.",
"Hi there!")
myRE = .RegularExpression~new
e = myRE~parse("This is a ???? flower.")
if e == 0 then do
do i over b
j = myRE~match(i)
say i~left(24) ">>" a.j
end
end
else
say "Error" e "occurred!"
exit
::requires "rxregexp.cls"
This is a nice flower. >> Does match regular expression This is a yellow flower. >> Does not match regular expression This is a blue flower. >> Does match regular expression Hi there! >> Does not match regular expression
Example 5.197. Class REGULAREXPRESSION - parse method
a.0 = "an invalid number!"
a.1 = "a valid number."
b = .array~of("1","42","0","5436412","1a","f43g")
myRE = .RegularExpression~new("[1-9][0-9]*")
do i over b
j = myRE~match(i)
say i "is" a.j
end
say
/* Now allow "hex" numbers and a single 0 */
if myRE~parse("0|([1-9a-f][0-9a-f]*)") == 0 then do
do i over b
j = myRE~match(i)
say i "is" a.j
end
end
else
say "invalid regular expression!"
exit
::requires "rxregexp.cls"
Example 5.198. Class REGULAREXPRESSION - parse method
str = "<p>Paragraph 1</p><p>Paragraph 2</p>"
myRE1 = .RegularExpression~new("<p>?*</p>","MINIMAL")
myRE1~match(str)
myRE2 = .RegularExpression~new("<p>?*</p>","MAXIMAL")
myRE2~match(str)
say "myRE1 (minimal) matched" str~substr(1,myRE1~position)
say "myRE2 (maximal) matched" str~substr(1,myRE2~position)
::requires "rxregexp.cls"
myRE1 (minimal) matched <p>Paragraph 1</p> myRE2 (maximal) matched <p>Paragraph 1</p><p>Paragraph 2</p>