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.
> > Any regex gurus out there?
>
>

Reply via email to