-1

I want to extract sentence starting from defined word with regex. Example text desired output below.

example_text = "Lorem ipsum dolorolo at sit amet, consectetur ipsumm adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco (laboris) nisi ut (aliquip) ex ea commodo consequat. [192.168.1.1:8080] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. **Excepteur** sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [192.168.1.254:80]"

re_pattern = r'\bExcepteur.*\b'

re_search = re.findall(re_pattern, example_text)

re_search

returns:

['Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [192.168.1.254:80']

I would like to do the similar query but without returning the search term: Excepteur

So the desired output would look like:

[sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [192.168.1.254:80']

How to change the re syntax?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Osku
  • 7
  • 2
  • You may think about [accepting an answer](https://stackoverflow.com/help/someone-answers) to reward those how helped you, or at least comment to explain what's missing ;) – azro Mar 27 '21 at 11:41

1 Answers1

0

Use a capturing goup

re_pattern = r'\bExcepteur(.*)\b'
re_search = re.findall(re_pattern, example_text)
azro
  • 53,056
  • 7
  • 34
  • 70