'Regex search pattern to extract string with 2 words limit
Looking to build some pattern using my_string as starting point to extract from my_string till Inc. i.e. Papa Johns some_text Inc
my_string_1 = 'Papa Johns'
my_string_1 = 'Inc.'
Need to search in any of the below sentences.
sent_1 = The company Papa Johns Retail Chain Inc. sells pizza, pastas etc.
sent_2 = The company Papa Johns Retail Chain., Inc. sells pizza, pastas etc.
sent_3 = The company Papa Johns Retail Chain, Inc. sells pizza, pastas etc.
sent_4 = The company Papa Johns Retail., Chain, Inc. sells pizza, pastas etc.
sent_5 = The company Papa Johns Retail, Inc. sells pizza, pastas etc.
I built a pattern pattern = '''Papa Johns (.{,30})Inc.''' and also this is working fine.
Is this possible if I do not use 30 chars condition but use 2 words limit (may be space split) to extract the required for all sentences.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
