>>import SE
Quote:
Quote:
Quote:
>>Editor = SE.SE ('sleeping=dead sleeping.htm== sleeping<==')
>>Editor ('This parrot <a href="sleeping.htm" target="new">is
sleeping</a>. Really, it is sleeping.'
'This parrot <a href="sleeping.htm" target="new">is sleeping</a>. Really, it
is dead.'
Or:
Quote:
Quote:
Quote:
>>Editor ( (name of htm file), (name of output file) )
Usage: You make an explicit list of what you want and don't want after
identifying the distinctions.
I am currently trying to upload SE to the Cheese Shop which seems to be
quite a procedure. So far I have only been successful uploading the
description, but not the program. Gudidance welcome. In the interim I can
send SE out individually by request.
Regards
Frederic
----- Original Message -----
From: "Martin Evans" <martin@browns-nospam.co.uk>
Newsgroups: comp.lang.python
To: <python-list@python.org>
Sent: Wednesday, July 05, 2006 1:34 PM
Subject: RegEx conditional search and replace
Quote:
Sorry, yet another REGEX question. I've been struggling with trying to
get
Quote:
a regular expression to do the following example in Python:
>
Search and replace all instances of "sleeping" with "dead".
>
This parrot is sleeping. Really, it is sleeping.
to
This parrot is dead. Really, it is dead.
>
>
But not if part of a link or inside a link:
>
This parrot <a href="sleeping.htm" target="new">is sleeping</a>. Really,
it
Quote:
is sleeping.
to
This parrot <a href="sleeping.htm" target="new">is sleeping</a>. Really,
it
Quote:
is dead.
>
>
This is the full extent of the "html" that would be seen in the text, the
rest of the page has already been processed. Luckily I can rely on the
formating always being consistent with the above example (the url will
normally by much longer in reality though). There may though be more than
one link present.
>
I'm hoping to use this to implement the automatic addition of links to
other
Quote:
areas of a website based on keywords found in the text.
>
I'm guessing this is a bit too much to ask for regex. If this is the case,
I'll add some more manual Python parsing to the string, but was hoping to
use it to learn more about regex.
>
Any pointers would be appreciated.
>
Martin
>
>
>
--
http://mail.python.org/mailman/listinfo/python-list