regmatch
regmatch |
Purpose
Compare text strings using a regular expression.
Synopsis
function regmatch(src:text, regex:string):boolean
function regmatch(src:text, regex:string, start:integer, flags:integer):boolean
function regmatch(src:text, regex:string, start:integer, flags:integer, mp:array(range) of textarea):boolean
Arguments
src
|
Text to process
|
||||||||||
regex
|
Regular expression
|
||||||||||
start
|
Position where to start the search
|
||||||||||
flags
|
Search options:
|
||||||||||
mp
|
Matching regions as an array of text area objects
|
Return value
true if a match was found.
Example
The following example extracts the value of 'pars2' from an input text consisting of lines of the form
name=value:
declarations m:array(range) of textarea t:text end-declarations t:="p1=10\npars2=234\nparam9=56\n" if regmatch(t,'pars2=\(.*\)$',1,REG_NEWLINE,m) then pars2:=parseint(t,m(1)) writeln(pars2) end-if
Further information
1. This function relies on the TRE library (see
http://laurikari.net/tre). Please refer to the documentation of this library for a detailed description of the supported expression syntax.
2. When the
mp argument is provided and the search is successful, the result of the processing is returned via this array as
textarea objects (see Section
The type textarea): the array cell
0 refers to the entire matching region and the following ones to each of the subexpressions.
Related topics
Module