Regular Expressions – string Array json RegExp Object
JavaScript string replace() Method With Example
Replace All the Simple Places That will show you each match the any regular Expressions with a new Replacing string
Syntax Of the Replace Method
string.replace(searchvalue, newvalue)
Example
<html> <head> <title>Using String Replace,match,split in JavaScript</title> </head> <body> <script type="text/javascript"> var re = /pakainfo/gi; var nstr = "pakainfo are round, and pakainfo are website."; var mystring = nstr.replace(re, "tutorials"); document.write(mystring ); </script> </body> </html>
Example 2
<html> <head> <title></title> </head> <body> <script type="text/javascript"> var re = /(\w+)\s(\w+)/; var nstr = "pakainfo com"; var mystring = nstr.replace(re, "$2, $1"); document.write(mystring); </script> </body> </html>
Match
Match Simple Returns of the array of the all parts of the each strings that simple matches Expressions.
Syntax Of the Match Method
string.match( param )
Example
<html> <head> <title>JavaScript The Regular Expressions and RegExp Object</title> </head> <body> <script type="text/javascript"> 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 ); </script> </body> </html>
Split
Split returns the simple array of the all the parts of the new string that are in all the string are in between in the new regular Expressions
Syntax Of the Split Method
string.split([separator][, limit]);
Example
<html> <head> <title>JavaScript strings and regular expressions</title> </head> <body> <script type="text/javascript"> var str = "pakainfo are round, and pakainfo are website."; var myspl = str.split(" ", 3); document.write( myspl ); </script> </body> </html>
Search
Search Returns the simple position of the level first new place that simple matches all the regular Expressions
Syntax Of the Search Method
string.search(regexp);
Example
<html> <head> <title>Using String Replace,match,split in JavaScript</title> </head> <body> <script type="text/javascript"> var re = /pakainfo/gi; var str = "pakainfo are round, and pakainfo are website."; if ( str.search(re) == -1 ){ document.write("Does not contain pakainfo" ); } else { document.write("Contains pakainfo" ); } </script> </body> </html>