Created
August 2, 2016 21:32
-
-
Save jianminchen/528872aa8853b22151325990506d60fc to your computer and use it in GitHub Desktop.
JavaScript String Match function - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
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 xmlns="http://www.w3.org/1999/xhtml"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> | |
<head> | |
<title></title> | |
<style> | |
p { | |
color: blue; | |
margin: 8px; | |
} | |
b { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<p><b>String </b> Match</p> | |
<p>this is a JavaScript String study practice </p> | |
<p id="test">test..</p> | |
<script type="text/javascript"> | |
var str = $( "p:first" ).text(); | |
var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
var regexp = /[A-E]/gi; | |
var matches_array = str.match(regexp); | |
$('#test').html = matches_array[0]; // include Jquery library | |
$( "p:last" ).html( matches_array.indexOf('d') ); | |
console.log(matches_array); | |
// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'] | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment