This example describes the search () usage of JavaScript regular expressions. Share to everyone for your reference.
The specific example code is as follows:
Copy Code code as follows:
<title>javascript Regular Expression search () Instance </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 Meixin/;
num = Str.search (reg);
num++;
$ ("ul"). Text ("Wang Meixin appears in the first" + num + "bit");
});
});
</script>
<style type= "Text/css" >
H5{color:blue;}
</style>
<body>
<p> This is Wang Meixin's picture. Do you? It's beautiful </p>
<button> dot I have a surprise </button>
<ul></ul>
</body>
I hope this article will help you with your JavaScript programming.