Last active
July 20, 2018 11:08
-
-
Save dgloriaweb/835ee7f86a516e96fe08929d37fe7f7f to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/garamex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script id="jsbin-javascript" src="js49.js"> | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var string = "Tom's contact number is 07343773652. tom is 45. TOM is in London. "; | |
string += "Mark's contact number is 07254332454. His age is 29."; | |
document.write(string); | |
document.write("<h1>REGEX tools</h1>"); | |
document.write("<br/><b>string.match</b><br/>"); | |
document.write(string.match(/\d+/g)); | |
document.write("<br/><b>string.replace</b><br/>"); | |
document.write(string.replace(/\d+/g, "xxx")); | |
document.write("<br/><b>string.split</b><br/>"); | |
document.write(string.split("H")); | |
document.write("<br/><b>string.search</b><br/>"); | |
document.write(string.search("H")); | |
document.write("<br/><b>global case insensitive search</b><br/>"); | |
document.write(string.match(/tom/gi)); | |
document.write("<br/><b>using RegEx</b><br/>"); | |
var regex=/\d+/g; | |
document.write(string.match(regex)); | |
document.write(string.replace(regex,"Undisclosed")); | |
document.write("<br/><b>using RegEx constructor (backslash has to be escaped)</b><br/>"); | |
var regexconst=new RegExp("\\d+","g"); | |
document.write(string.replace(regexconst,"Undisclosed")); | |
document.write("<br/><b>using exec</b><br/>"); | |
var result; | |
while((result=regexconst.exec(string))!= null){ | |
document.write(result[0]+"<br/>"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment