TRegExMatch
Used to extract the matched string when doing a search with regular expressions.
Example
' Match and capture group
' Extract fields from date string.
SuperStrict
Framework Text.RegEx
Import BRL.StandardIO
Local date:String = "The dates are: 12/30/1969, 06/04/1974 and 15/08/1980"
Print "Original : " + date + "~n"
Local regex:TRegEx = TRegEx.Create("(\d\d)[-/](\d\d)[-/](\d\d(?:\d\d)?)")
Try
Local match:TRegExMatch = regex.Find(date)
While match
Print "~nDate -"
For Local i:Int = 0 Until match.SubCount()
Print i + ": " + match.SubExp(i)
Next
match = regex.Find()
Wend
Catch e:TRegExException
Print "Error : " + e.toString()
End
End Try
Print "Done."
Methods
Method SubCount:Int()
Returns the number of subexpressions as a result of the search.
Method SubExp:String(matchNumber:Int = 0)
Returns the subexpression for matchNumber.
For expressions with no subpattern groups, this method can be used without a parameter to return the matched string.
Returns
The matched string, the subexpression string, or "" if matchNumber is out of range.
Method SubStart:Int(matchNumber:Int = 0)
Returns the start position for subexpression matchNumber.
For expressions with no subpattern groups, this method can be used without a parameter to return the start position of the matched string.
Returns
The start position, or -1 if matchNumber is out of range.
Method SubEnd:Int(matchNumber:Int = 0)
Returns the end position for subexpression matchNumber.
For expressions with no subpattern groups, this method can be used without a parameter to return the end position of the matched string.
Returns
The end position, or -1 if matchNumber is out of range.
Method SubExpByName:String(name:String)
Returns the subexpression for the given name.
Method SubIndexByName:Int(name:String)
Returns the index of the subexpression for the given name.
Method SubStartByName:Int(name:String)
Returns the start position of the subexpression for the given name.
Method SubEndByName:Int(name:String)
Returns the end position of the subexpression for the given name.