Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
 
PREVIOUS NEXT
Tagged: #js #store #regex #variable #combine
ADD COMMENT
Topic
Name
9+6 =