Answers for "js store regex in variable and combine"

0

js store regex in variable and combine

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
Posted by: Guest on July-01-2021

Code answers related to "js store regex in variable and combine"

Code answers related to "Javascript"

Browse Popular Code Answers by Language