I have this regex pattern: (1 Abc ([A-Z]+))|(Abc ([A-Z]+))|(1 ([A-Z]+)) that works as follows:
1 Abc TEST
Abc TEST
1 TEST
TEST
Link of the demo
It matches TEST in the first three cases, and does not match TEST in the last case.
The pattern looks a bit long, I want to make it shorter but keeping the same matching.
My tries ended with: (1 |Abc )([A-Z]+), but this pattern does not match TEST in the first string (link of the demo).
Any suggestions how to simplify the first pattern and keep the same matching?
EDIT:
To avoid all confusions, all what I want to capture is TEST when it is preceded by '1 ', 'Abc ' or '1 Abc '.
^(?:\w+ +)+([A-Z]+)$but it really depends on your actual input strings. As it stands, your question is not easily answerable.([A-Z]+)Part which is repeated multiple times. Depending on the prefix this will change the number of the capturing group. Thus you can not really change something and keep the exact same behaviour.1and/orAbcor any digit and/or any string? What about2 DEF TEST?(?<= )\S+$. It matches TEST in the first three cases, and does not match TEST in the last case.