0

I have a regex pattern that works fine. But I want to include literal string bar with the ? quantifier. This is giving me problems.

My original script was:

[A-Za-z]{1,3}:?-?\d?

Now, I want to match all of the following:

F
F2
FAO3
FOU-3
FO:5
Fbar
F2bar
FOE3bar
FWL-3bar
FO:5bar

The following does work, but it cannot be the "right"answer, it's so ugly. There has to be a more robust or direct way.

[A-Za-z]{1,3}:?-?\d?b?a?r?

I did try [A-Za-z]{1,3}:?-?\d?(bar)?, but, even though it works in Regex101, in my script this gives only:

bar
bar
bar
bar
physlexic
  • 826
  • 2
  • 9
  • 21

0 Answers0