How to join several (javascript) regular expressions into a single one?
For example, given [/^abcd$/,/^abxy$/,/^abz$/]
the output will be /^ab(cd|xy|z)$/
.
Is it even computationally possible?
How to join several (javascript) regular expressions into a single one?
For example, given [/^abcd$/,/^abxy$/,/^abz$/]
the output will be /^ab(cd|xy|z)$/
.
Is it even computationally possible?
It is quite easy to make such a tool for simple cases. Just put each pattern into parentheses and join them with "|". So for your example set of patterns it becomes:
/(^abcd$)|(^abxy$)|(^abz$)/
On a second thought, parentheses might not be necessary, so this will do:
/^abcd$|^abxy$|^abz$/
/((?:^abcd$)|(?:^abxy$)|(?:^abz$))/
maybe this is a better solution to group it in 1 matching group ?
|
) the different expressions. Your question implies that you want the tool to also "simplify" the expression. How do you measure the complexity of a regexp?