True.
match = re.compile('<(pre|PRE)(.*)/(pre|
pre)>',re.DOTALL).search(text)
should be
match = re.compile('<(pre|PRE)>(.*?)</(pre|
PRE)>',re.DOTALL).search(text)
On Jun 10, 11:14 pm, Jonathan Lundell <[email protected]> wrote:
> On Jun 10, 2010, at 10:00 PM, mr.freeze wrote:
>
> > Massimo's worked on the first try so I went with it!
>
> It may have a problem when there are two <pre> blocks.
>
>
>
> > On Jun 5, 2:05 pm, "mr.freeze" <[email protected]> wrote:
> >> Thanks Thadeus/Massimo. I'll give each a try and let you know what I
> >> find.
>
> >> On Jun 5, 12:57 pm, mdipierro <[email protected]> wrote:
>
> >>> Try this...
>
> >>> import uuid, re
> >>> subs={}
> >>> while True:
> >>> match = re.compile('<(pre|PRE)(.*)/(pre|
> >>> pre)>',re.DOTALL).search(text)
> >>> if not match: break
> >>> u=str(uuid.uuid4())
> >>> subs[u]=match.group()
> >>> text=text[:match.start()]+u+text[match.end():]
> >>> text=text.replace('\n','<br/>')
> >>> for key,value in subs.items():
> >>> text=text.replace(key,value)
> >>> return text
>
> >>> although there may be a better way in BeautifulSoup
>
> >>> On Jun 5, 12:14 pm, "mr.freeze" <[email protected]> wrote:
>
> >>>> I'm trying to replace all newline characters in a chunk of text with
> >>>> BRs except for those inside PRE tags. I can't seem to make it work.
> >>>> Anyregexgurus out there?