javascript 【正则表达】

1.正则表达式

1 //search()和replace()
2 
3 var str="This is a word names";
4 
5 var part=/word/i;
6 
7 str.search(part);    //返回寻找的位置---数字
8 
9 str.replace(part,"world");  //把word替换成world
1 //test()     exec()
2 var str="No Zuo No Die,Do you understand?"
3 
4 var part=/understand/i;
5 
6 part.test(str);   //返回true;
7 
8 
9 part.exec(str);  //返回字符串

 

posted @ 2018-02-03 14:26  Justice-V  阅读(75)  评论(0)    收藏  举报