This article describes the search() usage of javascript regular expressions. Share it for your reference.
The specific example code is as follows:
The code copy is as follows:
<html>
<head>
<title>Search() instance of javascript regular expression</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("button").click(function(){
var str = $("p").text();
var reg = /Wang Meiren/;
num = str.search(reg);
num++;
$("ul").text("The Wang Meiren appears in the second" + num + "bit");
});
});
</script>
<style type="text/css">
h5{color:blue;}
</style>
</head>
<body>
<h5>Find the location where "Miss Wang" appears</h5>
<p>Is this a photo of Wang Meiren? So beautiful</p>
<button>Click me to have surprise</button>
<ul></ul>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.