[Tutor] regular expression

Conrad Koziol arkamir at softhome.net
Thu Feb 12 20:50:58 EST 2004


What is the fastest way to search for a string and then surround it
<code> and </code> with something. Like so:

x = '<div> are not allowed, these arent either <br>'
<some code here>
x = '<code><div></code> are not allowed, these arent either
<code><br></code>'

The two ways this can be done is by subsituting the string like <div>
with <code><div></code> or inserting <code> and </code> before and after
it. Which one would be faster and how would I do it? I got as far as
creating the regular expression r'<[^<>]*>'

Thanks!!




More information about the Tutor mailing list