From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

RegEx.Search() As RegExMatch

Supported for all project types and targets.

Resumes searching in the previously provided TargetString (see below).


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

Supported for all project types and targets.

Finds SearchPattern in TargetString, beginning at SearchStartPosition if provided.


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.


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

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
If match <> Nil Then
result = match.SubExpressionString(0)
End If

match = re.Search
Loop Until match Is Nil