From Xojo Documentation
Regular Expressions (RegEx) are patterns that describe text. You can use regular expressions to find substrings in text and to make replacements within text.
These are common characters used to create RegEx patterns:
|.||wildcard, matches any character except
/r and /n
|\d||Matches a string of digits|
|\w||Matches a string of word characters|
|*||Repeat pattern zero or more times|
|+||Repeat pattern one or more times|
Your apps can search and replace text using regular expressions (often called RegEx), a pattern describes specific text to find in a string. You use the properties of the RegEx, RegExOptions and RegExMatch classes to define a regular expression and search or replace text using regular expressions. Regular Expressions can be a bit tricky to get the hang of, but they are fast and efficient ways to process text.
This code finds the first word in the text “Software development made easy”, returning “Software”:
Var match As RegExMatch
re.SearchPattern = "\w*"
match = re.Search("Software development made easy")
If match <> Nil Then
Here are some examples of other search patterns on the same text "Software development made easy":
|simple||Text Not Found|
Remember that a RegEx result (RegExMatch) may return more than one match. You should check RegExMatch.SubExpressionCount to see how many matches were returned.
Regular Expressions can also be used to replace strings in text. This code replaces “Software development” with “Programming”:
re.SearchPattern = "Software development"
re.ReplacementPattern = "Programming"
Var result As String
result = re.Replace("Software development made easy")
The result variable now contains “Programming made easy”. This removes HTML tags from source HTML:
re.SearchPattern = "<[^<>]+>"
re.ReplacementPattern = ""
Var html As String = "<p>Hello,</p><b/><p>There</p>"
Var plain As String = re.Replace(html)
While html.Compare(plain) <> 0
html = plain
plain = re.Replace