If **regexp** matches **this**, returns a new **Array** with item **0** equal to the
portion of **this** that matched the regular expression, item **1** equal to the first
capturing group in **regexp**, item **2** equal to the second capturing group in **regexp**,
and so on. The returned **Array** will also have an **index** property set to the
starting index of the match and an **input** property set to **this**.
If **regexp** doesn't match **this**, returns **null**.
var regexp = /(\d\d\d)-(\d\d\d\d)/;
var result = 'call me: 555-4385'.match(regexp);
if (result) {
console.log(result[0]);
console.log(result[1]);
console.log(result[2]);
console.log('index: ' + result.index);
console.log('input: ' + result.input);
}
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.10
----
prototype.replace(searchValue : String, replaceValue : String) : String
Returns a new **String** where the first occurrence of **searchValue** in **this** is
replaced with **replaceValue**.
var x = 'abcba'
console.log(x.replace('b', 'Z'));
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.11
----
prototype.replace(searchValue : String, replaceFunction(match : String, offset : Number, string : String) : String) : String
Returns a new **String** where the first occurrence of **searchValue** in **this** is
replaced with the value returned from calling **replaceFunction**.
The **match** parameter to
**replaceFunction** is the same as **searchValue**, **offset** is the index in **this**
where **searchValue** was found, and **string** is **this**.
var x = 'abcba';
var replaced = 'abcba'.replace('b', function(match, offset, string) {
console.log('found match of "' + match + '"');
console.log(' at offset ' + offset);
console.log(' of string "' + string + '"');
return match.toUpperCase();
});
console.log('replaced=' + replaced);
console.log('x=' + x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.11
----
prototype.replace(searchValue : RegExp, replaceValue : String) : String
Returns a new **String** where **searchValue** is replaced with **replaceValue**.
If **searchValue** is a %%/RegExp#global|global **RegExp**%%,
each match in **this** will be replaced. Otherwise, just the first match will
be replaced.
var x = 'abcba';
console.log(x.replace(/b/, 'Z'));
console.log(x.replace(/b/g, 'Z')); // global RegExp
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.11
----
prototype.replace(searchValue : RegExp, replaceFunction(match : String, capture1 : String, capture2 : String, ..., offset : Number, string : String) : String) : String
Returns a new **String** where **searchValue** matches in **this** is
replaced with the value returned from calling **replaceFunction**. If
**searchValue** is a %%/RegExp#global|global **RegExp**%%,
each match in **this** will be replaced. Otherwise, just the first match will
be replaced.
The **match** parameter to
**replaceFunction** is the same as **searchValue**,
the **capture** parameters are the values of the capture groups in **searchValue** (if any),
**offset** is the index in **this** where **searchValue** was found,
and **string** is **this**.
var x = 'abcba';
var replaced = 'abcba'.replace(/b/g, function(match, offset, string) {
console.log('found match of "' + match + '"');
console.log(' at offset ' + offset);
console.log(' of string "' + string + '"');
return match.toUpperCase();
});
console.log('replaced=' + replaced);
console.log('x=' + x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.11
----
prototype.search(regexp : RegExp) : Number
Executes **regexp** on **this** and returns the index of the first match.
Returns **-1** if **regexp** does not match **this**.
console.log('abcba'.search(/b/));
console.log('abcba'.search(/e/));
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.12
----
prototype.slice(startIndex : Number, [endIndex : Number]) : String
Returns a new string composed of the section of **this** between **start** and
**end-1**.
If **endIndex** is not specified, **this.length** is used instead. If
**startIndex** or **endIndex** is negative, **this.length** is added to it before performing
the substring. Similar to %%#substring|**substring()**%%.
var x = 'abcde';
console.log(x.slice(2));
console.log(x.slice(-2));
console.log(x.slice(2, 4));
console.log(x.slice(2, -1));
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.13
----
prototype.split(separator : String, [limit : Number]) : Array
Splits **this** at **separator** into an **Array** of **String**s. If
**limit** is specified, the returned array will contain no more than
**limit** items.
var x = 'abcba';
console.log(x.split('b'));
console.log(x.split('b', 2));
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.14
----
prototype.split(separator : RegExp, [limit : Number]) : Array
Splits **this** into an **Array** of **String**s. If **limit**
is specified, the returned array will contain no more than
**limit** items.
var x = 'abcba';
console.log(x.split(/b/));
console.log(x.split(/b/, 2));
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.14
----
prototype.substring(start : Number, [end : Number]) : String
Returns a new string composed of the section of **this** between **start** and
**end-1**.
Before performing the operation, **substring** may modifiy the effective values
of **start** and **end** as follows. If both **start** and **end** are
specified, and **end** is less than **start**, the values are swapped.
If **start** is less than **0**, it is replaced with **0**.
If **end** is negative, **this.length** is added to it before performing
the substring.
If **end** is not specified, **this.length** is used instead.
Similar to %%#slice|**slice()**%%.
var x = 'abcde';
console.log(x.substring(2));
console.log(x.substring(-2));
console.log(x.substring(2, 4));
console.log(x.substring(4, 2));
console.log(x.substring(2, -1));
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.15
----
prototype.toLowerCase() : String
Returns a copy of **this** where each character is lower case.
var x = 'aBCdEf';
console.log(x.toLowerCase());
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.16
----
prototype.toLocaleLowerCase() : String
Returns a copy of **this** where each character is lower case.
var x = 'aBCdEf';
console.log(x.toLocaleLowerCase());
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.17
----
prototype.toUpperCase() : String
Returns a copy of **this** where each character is upper case.
var x = 'aBCdEf';
console.log(x.toUpperCase());
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.18
----
prototype.toLocaleUpperCase() : String
Returns a copy of **this** where each character is upper case.
var x = 'aBCdEf';
console.log(x.toLocaleUpperCase());
console.log(x); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.19
----
prototype.trim() : String
Returns a copy of **this** with leading and trailing whitespace removed.
var x = ' \t ab c ';
console.log("'" + x.trim() + "'");
console.log("'" + x + "'"); // x is unchanged
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.4.20
----
fromCharCode(char0 : Number, [char1 : Number, [...]]) : String
Returns a new string composed of characters from the specified unicode values.
Use %%#charCodeAt|**charCodeAt()**%% to retrieve character codes from strings.
console.log(String.fromCharCode(97, 98, 99));
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.5.3.2