javascript match的使用及案例实操
- 作用: 在string中查找匹配值并返回, 若无返回null
- 用法
searchvalue: 必传, 规定要检索的字符串值.
reg: 必传, 穿匹配规则(reg有标志 g, 全匹配) - 案例
var str = "Hello world!"
str.match('world'); ---> ["world", index: 6, input: "Hello world!", groups: undefined]
str.match('World'); ---> null
str.match('worlld'); ---> null
str.match('world'); ---> world
var str="1 2 q 3 4 w 5 6 e 7 8 r d f"
str.match(/\d+/g) ---> 1 2 3 4 5 6 7 8