showing results for - "js store regex in variable and combine"
Delina
29 Jun 2018
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