RegEx.Search

From Xojo Documentation

Method

RegEx.Search([TargetString as String][,SearchStartPosition as Integer]) As RegExMatch

Supported for all project types and targets.

Finds SearchPattern in TargetString, beginning at SearchStartPosition.

SearchStartPosition is zero-based.

Notes

If it succeeds, it returns a RegExMatch. Both parameters are optional; if TargetString is omitted, it assumes the previous TargetString, so you will want to pass a TargetString the first time you call Search. If you call Search with a TargetString and omit SearchStartPosition, zero is assumed. If you call Search with no parameters after initially passing a TargetString, it assumes the previous TargetString and will begin the search where it left off in the previous call. This is the easiest way to find the next occurrence of SearchPattern in TargetString.

The RegExMatch will remember the ReplacementPattern specified at the time of the search.

Example

This example finds occurrences of "software" in the supplied string. Note that RegEx searches are case-insensitive by default:

Var re As New RegEx
Var match As RegExMatch

re.SearchPattern = "software"
match = re.Search("How much software can a Software Developer make?")

Var result As String
Do
If match <> Nil Then
result = match.SubExpressionString(0)
MessageBox(result)
End If

match = re.Search
Loop Until match Is Nil