js正则常用方法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>W3Cschool教程(w3cschool.cn)</title>
</head>
<body>
<h1>我的第一个 Web 页面</h1>
<button id = "demo">clock me</button>
<script>
document.getElementById("demo").addEventListener("click",myfun);
function myfun(){
//JavaScript 正则表达式
//定义:正则表达式是由一个字符序列形成的搜索模式
//语法:pattern/modifiers
//test方法
var a = new RegExp("mike");
document.write(a.test("mike is the best"));
//exec方法
var b = new RegExp("love");
document.write(b.exec("mike have love a girl some years ago"));
//compile方法
//replace方法
var c="her name is lina";
patt=/(li)?na/g;
patt.compile(patt);
document.write(c.replace(patt,"nana"));
//search方法
var d = "i wish lina has a happy life everyday";
document.write(d.search("lina"));
}
</script>
</body>
</html>
最新文章
- 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)
- MonkeyRunner测试一MonkeyRunner的使用
- android-sdks/build-tools/17.0.0/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
- POJ 3041 匈牙利算法模板题
- yii框架中应用jquery表单验证插件
- 关于 2dx v3.7 UIScale9Sprite的bug
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式
- Linux的进程优先级-邹立巍
- SQLite.dll混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。
- iOS7 NavigationController 右滑手势问题
- String的使用
- JavaScript的this和作用域
- xshell6 评估期已过 解决办法
- 初识ldap
- 约定优于配置---Java的eclipse项目配置
- redis学习链接收藏
- win10下乌龟git安装和使用(转)
- PHP 定界符
- The Win32 Rundll and Rundll32 Interface Related Topics
- AngularJS的初步学习(1)