MatchAllCallback - cRegEx
Calls a procedure for each match in the subject string
Type: Function
Return Data Type: Integer
Parameters
| Parameter | Type | Description |
|---|---|---|
| sSubject | String | The host string to run the regular expression on |
| hoObj | Handle | Handle of the cRegEx object |
| hoMessage | Handle | Handle of the procedure to call as callback method |
Syntax
Function MatchAllCallback String sSubject Handle hoObj Handle hoMessage Returns Integer
Call Example
Get MatchAllCallback sSubject hoObj hoMessage to IntegerVariable
Description
Calls the passed procedure for every match it finds on the subject string. To this procedure it will pass the match name, value and offsets. The procedure will be called for the full matches (sName will be "full_match") and the individual matching groups. If the group is a named matching group (?..) then sName will contain that name, else with be the matching group number as a string. The procedure will return the number of matches.
Signature of Callback Method:
Procedure MatchCallback String sName String sValue Integer iFromChar Integer iToChar
Sample
In the example below EmailCallback will be called for every email address it finds.
Object oEmailFinder is a cRegEx
Set psExpression to "[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+"
Set pbIgnoreCase to True
End_Object
Procedure EmailCallBack String sName String sValue Integer iFromChar Integer iToChar
Showln "sName: " sName ", sValue: " sValue ", iFromChar: " iFromChar ", iToChar: " iToChar
End_Procedure
Integer iMatches
Get MatchAllCallback of oEmailFinder """
Donny,
Can you please send the tickets to john@dataaccess.com? You can invoice info@dataaccess.eu for it.
Regards,
""" Self (RefProc(EmailCallBack)) to iMatches
The output of this example will be:
sName: full_match, sValue: john@dataaccess.com, iFromChar: 44, iToChar: 63
sName: full_match, sValue: info@dataaccess.eu, iFromChar: 81, iToChar: 99
Return Value
The number of matches (0 if no match).