I have the following text below that I am trying to parse into match groups and matches for those groups:
The Big Store is a retail building.
5 Washington Blvd W. in San Francisco - A beautiful Stage.
555-123-456
Here is the output I am looking for:
Match Group 1 = "Big Store"
Match Group 1 Matches = "[Store]"
Match Group 2 = "5 Washington Blvd W. in San Francisco - A beautiful Stage"
Match Group 2 Matches = "[ Francisco, Beautiful]"
Match Group 3 = "555-123-456"
Match Group 3 Matches = "[]"
With that being said, I am looking to create a regex that matches on:
- Francisco
- Beautiful
- Store
How can I achieve this using regex
CodePudding user response:
You can do this by matching for the words you need, divided by |
and included in the case insensitive zone, delimited by (?i)<case insensitive matching>(?-i)
.
(?i)store|francisco|beautiful(?-i)
When you cycle the re.find
function through all lines, you'll get the Match Group Matches
you're looking for.
Does it work as you expected to?