We have two ways of referring to the same system:
- tr12345
- fr12345
Right now I have one regular expression per variation, e.g
/(?:^|^\s|[^\/a-zA-Z0-9])tr([0-9]+).*$/img
/(?:^|^\s|[^\/a-zA-Z0-9])fr([0-9]+).*$/img
This works fine, but I thought it could be more efficient by combining the two. I saw from other articles that you can use the alternation |
to match variations. Do I need to repeat the regex after the "tr" if I'm trying to match both?
E.g is something like this possible?
/(?:^|^\s|[^\/a-zA-Z0-9])tr|fr([0-9]+).*$/img
Example input1:
tr12345
Desired output1:
12345
Example input2:
fr123456
Desired output2:
123456
I've been playing with it here: https://regex101.com/r/FUCmv0/2