SBM ModScript Reference → Programming SBM ModScript → Object Types → Regex → Regex Compile() Method
Compiles a regular expression.
Parameter | Type | Description |
---|---|---|
pattern |
string |
Holds the regular expression pattern to be compiled. |
options |
int |
Indicates regular expression behavior, such as case sensitivity. See RegexOptionBitsConstants. Bits can be combined using the bitwise OR operator: | . |
Type | Description |
---|---|
bool |
Returns false if Compile() fails. |
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
None.
Copyright © 2007–2018 Serena Software, Inc., a Micro Focus company. All rights reserved.