Product Site

5.4.15.2. match

This method tries to match string to the regular expression set by calls to the new or parse method.

With option MAXIMAL in effect, it will successfully match only if the whole string matches. With option MINIMAL in effect, any successful match will always start at the first character of string, but doesn't necessarily have to cover the full string. Thus a match will always be a leading part of string.

Method match returns 0 for an unsuccessful match and 1 for a successful match.
Example 5.275. RegularExpression class — match method
str = "<p>Paragraph 1</p><p>Paragraph 2</p>"
re1 = .RegularExpression~new("<p>?*</p>", "MINIMAL")
re1~match(str)
re2 = .RegularExpression~new("<p>?*</p>", "MAXIMAL")
re2~match(str)

say "re1 (minimal) matched" str~substr(1, re1~position)
say "re2 (maximal) matched" str~substr(1, re2~position)

::requires "rxregexp.cls"

Output:
re1 (minimal) matched <p>Paragraph 1</p>
re2 (maximal) matched <p>Paragraph 1</p><p>Paragraph 2</p>