Interested in improving this site? Please check the To Do page.
Back to Regular Expression (re) Verbs
re.visit
Traverses all matches in the target string and calls the callback script for each match.
Syntax
re.visit (cp, s, adrCallBack, flMakeGroups, flMakeNamedGroups, maxRuns)
Params
- cp is a binary param containing the compiled pattern that was returned by a call to “re.compile”.
- s is a string param containing the target string.
- adrCallback is an address param specifying a script to be called for every match found in the target string.
- flMakeGroups is an optional boolean param determining whether the match info table passed to the callback will contain information about sub-strings captured by parentheses in the pattern. Defaults to false.
- flMakeNamedGroups is an optional boolean param determining whether the match info table passed to the callback will contain information about sub-strings captured by named parentheses in the pattern. Defaults to false.
- maxRuns is an optional number param specifying the upper limit on the number of times the callback script will be called. Defaults to infinity.
Returns
True, or false if the callback script returned false.
Examples
on testCallback (adrTable)
dialog.notify (string(adrTable^));
return (true)
local (cp = re.compile ("<([^>]+)>", flCaseSensitive: false))
re.visit (cp, "<A href='index.html'> <A href='index2.html'>", @testCallback)
true
Errors
An error will be generated if the cp param is not a valid byte-code representation of a regular expression.
Notes
- For each match of the compiled pattern in the target string, the callback script is called with the address of a match info table whose contents follows the same conventions as that generated by “re.match”, including the meaning of the optional flMakeGroups and flMakeNamedGroups params.
- The callback script should return a boolean value indicating whether further attempts to match the pattern should be made.
- If the maxRuns parameter is less than one, the callback script will be called only once.
- The kernel implementation of the re verbs is based on the Perl Compatible Regular Expressions (PCRE) library. This is the same library used by Python, Apache, and PHP. Mandatory excerpt from the PCRE license:
- Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England.
- The source code for the PCRE library is available for download from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/