I have the following RE that needs to match starting on the end of the string.
Strings:
AAA. A ZZZ-X37
AAA 4X X9 A ZZZ-X37
AAA 4X A ZZZ-X37
RE:
^(?<g1>\s?[a-zA-Z\.]*)(?<g2>\s?[a-zA-Z\d]*)?(?<g3>\s?[a-zA-Z\d]*)?(?<g4>\s?[a-zA-Z]*)(?:\s?(?P<CAPT1>[A-Z]*)(?:-)?(?P<CAPT2>[\w\d]*)(?:-.{2})?)$
CAPT1 needs to capture the ZZZ on all the cases, but on example #1 and #3 its not getting it. I tried making the g2 and g3 group optional, but didnt seem to make a difference.
My idea now is to start matching by the end of the string, so that would capture what I need first, but if g2 and g3 could all be optional, then I would prefer it.