RegExp : Object RegExp represents a regular expression that can be used for searching and extracting parts of %%/String|**String**%%s. Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10 ---- RegExp(pattern : String, [flags : String]) : RegExp Same as %%#new_RegExp_String_String|**new RegExp(pattern, flags)**%%. Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.3.1 ---- new RegExp(pattern : String, [flags : String]) : RegExp Constructs a new **RegExp** for the specified **pattern**. If **flags** contains **'g'**, %%#global|**this.global**%% will be set to **true**. If **flags** contains **'i'**, %%#ignoreCase|**this.ignoreCase**%% will be set to **true**. If **flags** contains **'m'**, %%#multiline|**this.multiline**%% will be set to **true**. **RegExp**s can also be constructed using **/pattern/flags** syntax. // The following are equivalent var x = /pattern/i; var y = RegExp('pattern', 'i'); var z = new RegExp('pattern', 'i'); Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.4.1 ---- prototype.exec(str : String) : Array If **this** matches **str**, returns a new **Array** with item **0** equal to the portion of **str** that matched the regular expression, item **1** equal to the first capturing group in **this**, item **2** equal to the second capturing group in **this**, and so on. If **this** doesn't match **str**, returns **null**. var regexp = /(\d\d\d)-(\d\d\d\d)/; var result = regexp.exec('call me: 555-4385'); if (result) { console.log(result[0]); console.log(result[1]); console.log(result[2]); } Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.6.2 ---- prototype.test(str : String) : Boolean Returns **true** if **this** matches **str**. var regexp = /(\d\d\d)-(\d\d\d\d)/; console.log(regexp.test('555-4385')); console.log(regexp.test('KL5-4385')); Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.6.3 ---- instance.source : String The pattern of this regular expression. var regexp = /(\d\d\d)-(\d\d\d\d)/; console.log(regexp); console.log(regexp.source); ReadOnly: true Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.1 ---- instance.global : Boolean **true** if the **RegExp** was created with the **'g'** flag. Global **RegExp**s will match each place %%#source|**this.source**%% occurs in the string, not just the first match. console.log('abcba'.replace(/b/, 'X')); console.log('abcba'.replace(/b/g, 'X')); ReadOnly: true Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.2 ---- instance.ignoreCase : Boolean **true** if the **RegExp** was created with the **'i'** flag. IgnoreCase **RegExp**s will do case insensitive matching. console.log(/hello/.test('Hello')); console.log(/hello/i.test('Hello')); ReadOnly: true Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.3 ---- instance.multiline : Boolean **true** if the **RegExp** was created with the **'m'** flag. Multiline **RegExp**s will match **'^'** to the beginning of lines as well as the beginning of the string and match **'$'** to the end of lines as well as the end of the string. var str = 'hello\nworld'; console.log(/^world/.test(str)); console.log(/^world/m.test(str)); ReadOnly: true Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.4 ---- instance.lastIndex : Number The starting index into the string for the next search. Is automatically set to the index after a successful match. This property only applies if the **RegExp** is %%#global|**global**%%. var regexp = /foo|bar|baz/g; console.log(regexp.exec('foo bar baz')[0]); console.log(regexp.lastIndex); regexp.lastIndex = 5; console.log(regexp.exec('foo bar baz')[0]); Spec: http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.5