Trying to match these input strings with three comparable groups ( link Regex101 ):
| input string | x | y | z |
------------------------------------
I | a | a | | |
II | a - b | a | b | |
III | a - b-c | a | b-c | |
IV | a - b, 12 | a | b | 12 |
V | a - 12 | a | | 12 |
VI | 12 | | | 12 |
So, the anatomy of the input lines is as follows:
- optional first part with free text before
hyphenwith surrounding space ( -) or the input line ends - optional second part with any character after the first hyphen with a surrounding space until
commaor until the end of the input ends - optionally exactly two digits at the end
I tried many different solutions, this is my current attempt:
^(?P<x>.*)(?:-)(?P<y>.*)(?<!\d)(?P<z>\d{0,2})(?!\d)$
It handles the scripts II, IVand VOK (it should also execute some piece of space):
Iand VIdo not return at allIII ,