I got some strings to search for a match with regular expressions.
foo
AB0001
AB0002 foo
foo AB0003
foo AB0004A AB0004.1
AB0005.1 foo AB0005A bar AB0005
The desired matches are one ID per line while IDs with a letter at the end should be prioritized, whereas IDs with a .1 should be ignored.
foo -> no match
AB0001 -> AB0001
AB0002 foo -> AB0002
foo AB0003.1 -> no match
foo AB0004A AB0004.1 -> AB0004A
AB0005.1 foo AB0005A bar AB0005 -> AB0005A
I thought I could easily use the priority given by the alternation |
symbol to prioritize the ID with a capital letter at the end but nevertheless there are always given multiple matches.
My suggestion: regex101.com/r/yP5kX4/1
Offtopic: When to use the whole RegEx starting with ^
ending with $
and work with capture/non-capturing groups and when should I write RegEx as short as possible?