Programming :  Student Freelance Forum For Work Experience Builders' (CertificationPoint) The fastest message board... ever.
 
Regex capture phrase, plus word before and word after
Posted by: adcertpoint (Moderator)
Date: July 22, 2021 07:18PM

With Python re, I'm trying to capture a phrase, plus the word before and word after in a single return.

I.e. From the sentence...
We want to see this phrase here and then again!
Return
see this phrase here

The closest I have gotten is ...

>>> s = 'We want to see this phrase here and then again!'
>>> re.search("\w*\sthis phrase\w*\s",s)
<_sre.SRE_Match object; span=(11, 27), match='see this phrase '>

Options: ReplyQuote


Sorry, only registered users may post in this forum.
This forum powered by Phorum.