file/re search and sub problem
Darrell Gallion
darrell at dorb.com
Wed Jun 28 20:13:53 EDT 2000
Here's two solutions.
>>> s='11ebitda</td>'
>>> re.sub('(?i)[^A-Z]ebitda[^A-Z]','EBITDA', s)
'1EBITDA/td>'
>>> re.sub('(?i)(?![^A-Z])ebitda(?=[^A-Z])','EBITDA', s)
'11EBITDA</td>'
>>> re.sub('(?i)([^A-Z])ebitda([^A-Z])','\g<1>EBITDA\g<2>', s)
'11EBITDA</td>'
----- Original Message -----
From: <tiddlerdeja at my-deja.com>
>
> I have a re:
> wilf_re = re.compile('[^A-Z]ebitda[^A-Z]', re.IGNORECASE)
>
> And I do a search and replace
> if wilf_re.search(file):
>
> # perform the substitution
> new_file = wilf_re.sub(" EBITDA", file)
>
> This isn't really what I want. If I have
> ebitda</td>
> It replaces it with
> EBITDA/td>
>
>
> Can someone tell me how I go about getting:
> EBITDA</td>
More information about the Python-list
mailing list