js concatenate regex

Solutions on MaxInterview for js concatenate regex by the best coders in the world

showing results for - "js concatenate regex"
Alya
01 Mar 2019
1const a = /a/
2const b = /b/
3// Concatenate two Regular Expressions with an OR |
4const c = new RegExp( a.source + "|" + b.source );
5// c --> /a|b/
6
7"a".match(c)
8// ["a", index: 0, input: "a", groups: undefined]
9"b".match(c)
10// ["b", index: 0, input: "b", groups: undefined]
11"c".match(c)
12// null
similar questions
queries leading to this page
js concatenate regex