📜  js 将正则表达式存储在变量中并结合 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:12.877000             🧑  作者: Mango

代码示例1
const a = /a/
const b = /b/
// Concatenate two Regular Expressions with an OR |
const c = new RegExp( a.source + "|" + b.source );
// c --> /a|b/

"a".match(c)
// ["a", index: 0, input: "a", groups: undefined]
"b".match(c)
// ["b", index: 0, input: "b", groups: undefined]
"c".match(c)
// null