溫馨提示×

javascript正則函數都有哪些

養魚的貓咪
194
2021-04-12 13:17:39
欄目: 編程語言

javascript中的正則函數有:1.test,檢測一個字符串是否匹配某個模式;2.match,在字符串內檢索指定的值;3.replace,在字符串中替換字符;4.search,檢索字符串中指定的子字符串;

javascript正則函數都有哪些

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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女