欢迎光临
我们一直在努力

javascript正则函数都有哪些

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("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

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。