A Matcher object is used to search for a pattern in a string. Regex.Matcher returns a matcher object for a specific pattern and specific text. Example: Dimtext, patternAsString text = "This is an interesting sentence with two numbers: 123456 and 7890." pattern = "\d+"'one or more digits DimMatcher1AsMatcher Matcher1 = Regex.Matcher(pattern, text)
DoWhileMatcher1.Find Log("Found: " & Matcher1.Match)
Loop
Searches for the next substring that matches the pattern. Returns True if such a match was found. Example: Dimtext, patternAsString text = "This is an interesting sentence with two numbers: 123456 and 7890." pattern = "\d+"'one or more digits DimMatcher1AsMatcher Matcher1 = Regex.Matcher(pattern, text)
DoWhileMatcher1.Find Log("Found: " & Matcher1.Match)
Loop
GetEnd (IndexAsInt) AsInt
Returns the end offset of the specified captured group. Use GetEnd(0) to get the end offset of the whole match.
GetStart (IndexAsInt) AsInt
Returns the start offset of the specified captured group. Use GetStart(0) to get the start offset of the whole match.
Group (IndexAsInt) AsString
Returns the value of the specified captured group. Group(0) returns the whole match.
GroupCountAsInt [read only]
Returns the number of capturing groups in the pattern. Note that the number returned does not include group(0) which is the whole match.
IsInitializedAsBoolean
MatchAsString [read only]
Returns the matched value. This is the same as calling Group(0).
Regex is a predefined object that contains regular expressions methods. All methods receive a 'pattern' string. This is the regular expression pattern. More information about the regular expression engine can be found here: Pattern Javadoc Regular expression in Basic4android tutorial.
Tests whether the given text is a match for the given pattern. The whole text should match the pattern. Use Matcher if you look for a substring that matches the pattern. Example: IfRegex.IsMatch("\d\d\d", EditText1.Text) = FalseThen ...
Tests whether the given text is a match for the given pattern. Options - One or more pattern options. These options can be combined with Bit.Or.
Matcher (PatternAsString, TextAsString) AsMatcher
Returns a Matcher object which can be used to find matches of the given pattern in the text. Example: Dimtext, patternAsString text = "This is an interesting sentence with two numbers: 123456 and 7890." pattern = "\d+"'one or more digits DimMatcher1AsMatcher Matcher1 = Regex.Matcher(pattern, text)
DoWhileMatcher1.Find Log("Found: " & Matcher1.Match)
Loop
Replaces all the matches in the text based on the specified pattern and template. Example: Log(Regex.Replace("\d", "1 2 3 4", "-$0-")) '-1- -2- -3- -4-
Similar to Replace. Allows setting the regex options.
Split (PatternAsString, TextAsString) AsString()
Splits the given text around matches of the pattern. Note that trailing empty matches will be removed. Example: Dimcomponents() AsString components = Regex.Split(",", "abc,def,,ghi") 'returns: "abc", "def", "", "ghi"