Charles.Forsyth20060303-partialeea662d19 years agoHistory
108 lines · 2.4 KB · Text
RawDownload
.TH REGEX 2.SH NAMEregex \- regular expression recognizer module.SH SYNOPSIS.EXinclude "regex.m";regex := load Regex Regex->PATH; compile:   fn(e: string, flag: int): (Re, string);execute:   fn(x: Re; s: string): array of (int,int);executese: fn(x: Re, s: string, se: (int, int), bol: int, eol: int):			array of (int, int);.EE.SH DESCRIPTIONRegular expressions are defined by.IR regexp (6)..B Compilereturns (as the first element of the result tuple)a compiled form of the regular expression given in string .IR e .If.I eis not a valid regular expression,.B compilereturns the tuple.BI "(nil" ", diag" )where.I diagis a diagnostic string.The effect of .I flagis described below..PP.B Executematches the compiled regular expression.I xagainst string.I s.It returns.B nilon no match, otherwise it returns an array.The element with index 0 gives the character positionsof the first character of some longest leftmost match andthe first character beyond the match.If the compilation.I flagwas 0, there are no more elements.If.I flagwas 1, there is one element for each pair ofparentheses in the regular expression, countingleft parentheses left to right starting at 1.The.IR n thelement gives the position of the last match to the .IR n thparenthesized subexpression, or (\-1,\-1) if the subexpressiondoes not participate in the overall match..PP.B Executeseis similar to.B executebut allows the start and end points in the string to be specified,as tuple.IR se :.BI ( "start , end" ) ,where.I startis the index in.I sof the initial character to be matched,and.I endis the index in.I sof the first character beyond the substring to be matched(and can be the length of.IR s ).If.I bolis non-zero, theinitial character is at the beginning of a line,allowing an initial match by the regular expression operator.RB ` ^ ';if.I eolis non-zero, thelast character is at the end of a line, allowing a matchby the operator `\f5$\fP'..SH EXAMPLES.EX(re, nil) := regex->compile("(thick )*(chocolate |raspberry )?"+			"(topp|fill)ing", 0); (re, nil) := regex->compile("[ABCb-z]+", 0);a := regex->execute(re, s:="aAbBcCdD");(beg, end) := a[0];s[beg:end] == "AbBcCd"; (re, nil) := regex->compile("a*b*", 0);a := regex->execute(re, "bbaabb");(beg, end) := a[0];(beg, end) == (0,2);.EE.SH SOURCE.B /appl/lib/regex.b.SH SEE ALSO.IR regexp (6)