Read Me - Common Public License V1.0 - Copyright Notice(©)

pos


>>-pos-(-haystack-)----------------------------------------><

This method tries to locate a string defined by the regular expression on the "new" invocation or on the "parse" invocation in the given [haystack] string. It returns 0 on an unsuccessful match or the starting position on a successful match. The end position of the match can be retrieved with the position method ().

Class REGULAREXPRESSION - haystack method


str = "It is the year 2002!"
myRE = .RegularExpression~new("[1-9][0-9]*")
begin = myRE~pos(str)
if begin > 0 then do
  year = str~substr(begin, myRE~position - begin + 1)
  say "Found the number" year "in this sentence."
end

::requires "rxregexp.cls"

Output:


Found the number 2002 in this sentence.

Read Me - Common Public License V1.0 - Copyright Notice(©)