Reputation: 13662
I have the following example text
text = '. Double-Decker advances to 1st on throwing error. Chris Parmelee to 3rd.'
I want to capture the following information
['Double-Decker', '1st']
['Chris Parmelee', '3rd']
I am trying the following regex
'\. ([A-Za-z\'\-\s]*) (?:advances)*to (1st|2nd|3rd)'
But it is matching
['Double-Decker advances', '1st']
['Chris Parmelee' , '3rd']
How should I be dealing with the unwanted optional word advances
?
Upvotes: 0
Views: 47
Reputation: 7880
Use:
\. ([A-Za-z\'\-\s]*?) (?:advances )*to (1st|2nd|3rd)
In your regex there are two small errors:
*
operator is greedy: you should use [A-Za-z\'\-\s]*?
advances
does not have a space after, so it won't ever match "advances to".Upvotes: 2