javascript中的正则函数有:1.test,检测一个字符串是否匹配某个模式;2.match,在字符串内检索指定的值;3.replace,在字符串中替换字符;4.search,检索字符串中指定的子字符串;
javascript中的正则函数有以下几种
1.test
javascript中test函数的作用是用于检测一个字符串是否匹配某个模式。
test函数使用方法:
var str = \"hello world!\";
var patt1 = new RegExp(\"world\");
var result = patt1.test(str);
document.write(result); //返回true
2.match
javascript中match函数的作用是用于在字符串内检索指定的值。
match函数使用方法:
var str=\"Hello world!\"
document.write(str.match(\活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看"world!\")) //返回world!
document.write(str.match(\"worlld\")) //返回null
3.replace
javascript中replace函数的作用是用于在字符串中替换字符。
replace函数使用方法:
var str=\"Hello world!\"
document.write(str.replace(/world!/, \"China!\")) //返回Hello China!
4.search
javascript中search函数的作用是用于检索字符串中指定的子字符串。
search函数使用方法:
var str=\"Hello world!\"
document.write(str.search(/world!/)) //返回6
《javascript正则函数都有哪些》来自互联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...