-
Notifications
You must be signed in to change notification settings - Fork 12
String.Match
boxgaming edited this page Aug 5, 2025
·
3 revisions
Retrieves the result of matching this string against a regular expression. Results are returned as an array of strings.
String.Match s$, regex$_, results$() [, g]
- The s$ parameter contains the string to split.
- The regex$ parameter contains the regular expression that will be used to search the given string in s$.
- The results$() parameter is a string array that will contain the results of the match.
- The optional group identifier parameter, g, can be used when the regular expression contains a group pattern. This can either be the group number or group name.
Import String From "lib/lang/string.bas"
Dim s As String
s = "The quick brown fox jumped over the lazy dog. It barked."
String.Match s, "(fox|dog|wolf)", result()
PrintResults result()
String.Match s, "[A-Z]", result()
PrintResults result()
' reference match results by group number
s = "<list><item>value one</item><item>value two</item></list>"
String.Match s, "<item>([^<]+)<\/item>", results(), 1
PrintResults results()
' reference match results by group name
String.Match s, "<item>(?<itemvalue>[^<]+)<\/item>", results(), "itemvalue"
PrintResults results()
Sub PrintResults (result() As String)
Print "-------------["; UBound(result); "]----------------"
For i=1 To UBound(result)
Print result(i)
Next i
End Sub-------------[2]----------------
fox
dog
-------------[2]----------------
T
I
-------------[2]----------------
value one
value two
-------------[2]----------------
value one
value two