Product Site

5.4.15.4. pos

This method tries to locate the regular expression set by calls to the new or parse method in the given haystack string.

Method pos returns 0 for an unsuccessful match, or the starting position for a successful match. The end position of the match can be retrieved with the position method.
Example 5.278. RegularExpression class — haystack method
text = "It's the year 2016!"
re = .RegularExpression~new("[1-9][0-9]*")
begin = re~pos(text)
if begin > 0 then
  do
    year = text~substr(begin, re~position - begin + 1)
    say "Found the number" year "in this sentence."
  end

::requires rxregexp.cls

Output:
Found the number 2016 in this sentence.