SBM ModScript Reference → Programming SBM ModScript → Object Types → Regex → Regex Matches() Method
Executes a search for a match in a string.
Parameter | Type | Description |
---|---|---|
value |
string |
Holds the string to be searched. |
offset |
int |
The index that denotes where in the string to start the search; use 0 to start at the beginning. |
start |
int& |
(Output) If a match was found, the zero-based index of the beginning of the matched-text. |
end |
int& |
(Output) If a match was found, the zero-based index of the end of the matched-text. |
Type | Description |
---|---|
bool |
Returns true if a match was found. |
SBM ModScript version: 11.3.
var regex = Regex(); //To test for a valid phone number var subCheck = "(\\+\\d{1,2}\\s*)?\\(?\\d{3}\\)?\\s*[\\.-]?\\s*\\d{3}\\s*[\\.-]?\\s*\\d{4}"; var testNumbers = "123-456-7890 | (123)456-7890 | 123 456 7890 | 123,456,7890 | +91 (123) 456-7890"; regex.Compile(subCheck, RegexOptionBitsConstants.IGNORECASE | RegexOptionBitsConstants.MULTILINE); if ( regex.Matches(testNumbers) ) { Ext.WriteStream("Matches:<br />${regex.GroupVal(0)}"); while( regex.MatchesAgain() ) { Ext.WriteStream("<br />${regex.GroupVal(0)}"); } }
Result:
Matches: 123-456-7890 (123)456-7890 123 456 7890 +91 (123) 456-7890
An integer zero-based index offset that denotes where to start in the value passed in and output integer references of start and end can be provided, which identifies where the match started and ended in the value passed in. The offset makes it possible to invoke this call multiple times to find all matches in the value passed in.
Copyright © 2007–2018 Serena Software, Inc., a Micro Focus company. All rights reserved.