js_tutorial

Javascript var index =

Javascript var index = str1.localeCompare( "XYZ" ); document.write("localeCompare first :" + index ); document.write("" ); var index = str1.localeCompare( "AbCD ?" ); document.write("localeCompare second :" + index ); Output localeCompare first :-1 localeCompare second :1 match () This method is used to retrieve the matches when matching a string against a regular expression. Syntax Use the following syntax to use the match() method. string.match ( param ) Argument Details param : A regular expression object. Return Value If the regular expression does not include the g flag, it returns the same result as regexp.exec(string). If the regular expression includes the g flag, the method returns an Array containing all the matches. Example Try the following example. 148

Javascript JavaScript String match() Method var str = "For more information, see Chapter 3.4.5.1"; var re = /(chapter \d+(\.\d)*)/i; var found = str.match( re ); document.write(found ); Output Chapter 3.4.5.1,Chapter 3.4.5.1,.1 replace () This method finds a match between a regular expression and a string, and replaces the matched substring with a new substring. The replacement string can include the following special replacement patterns: Pattern Inserts $$ Inserts a "$". $& Inserts the matched substring. $` Inserts the portion of the string that precedes the matched substring. $' Inserts the portion of the string that follows the matched 149