js

test和replace和exec和match的区别

2020-11-18  本文已影响0人  一土二月鸟

test和exec属于 RegExp的方法

/./.test(1) // true
/1/.exec('123')

replace和match为字符串的方法

"abca".match('a') // ["a", index: 0, input: "abca", groups: undefined]
"abca".match(/a/) //  ["a", index: 0, input: "abca", groups: undefined]
"abca".match(/a/g) //  ['a', 'a']
上一篇 下一篇

猜你喜欢

热点阅读