I want to achieve the following:
say I have two regex, regex1
and regex2
. I want to construct a new regex that is of 'prefix_regex1 | prefix_regex2'
, what syntax should I use to share the prefix, I tried 'prefix_(regex1|regex2)'
but it's not working, since I think it's confused on the bracket used as group rather than making the |
precedence higher.
example:
I have two string that both should match the pattern:
prefix_123
prefix_abc
I wrote this pattern: prefix_(\d*|\D*)
that tries to capture both cases, but when I run it against prefix_abc
it's only matching prefix_
, not the entire string.