Regex Compile() Method

Compiles a regular expression.

Function Signature

 bool Compile( string pattern [, int options] )

Parameters

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: | .

Return

Type Description

bool

Returns false if Compile() fails.

Technical Details

SBM ModScript version: 11.3.

Example

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 

Notes

None.

Related Topics

Regex