I'm trying to write regex for the following possible cases. I use re.finditer()
along with re.IGNORECASE
to match with the strings. Possible cases and the corresponding matches are
'vessel eta: 12-10-19'
should match with'vessel eta: '
'vessel eta 12-10-19'
should match with'vessel eta '
'etd eta : 12/10/19'
should match with'etd eta '
'eta SIN: 12/10/19'
should match with'eta SIN:'
'eta : 12-10-19
should match with'eta :'
'eta: 12-10-19'
should match with'eta: '
'eta. 12-10-19'
should match with'eta. '
'eta 12-10-19'
should match with'eta '
Till now, I wrote this :
((vessel)|(ETD))?(\s\.\:)?(ETA)[\s\.\:]{1,3}?(SIN)?[\s\.\:]?
But as per regex101, this matches with all except the first three cases, where the first word (whether it's 'vessel'
or 'etd'
) is not being captured.
What's wrong with my regex?