Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've got a script which essentially restricts HTML within a post to certain tags (much like many sites), and automatically adds 'BR' tags to new lines. One of the tags I'd like to allow is the 'PRE' tag, which should not have a break tag to break lines.
I use the regex 's/\n/<BR>\n/gs' to add the break tags to the whole comment, then I'd like to remove the tags in PRE by using something like:
while(/<pre>(.*?)<\/pre>/) { $1 =~ s/<BR>\n/\n/gs; }
Naturally this doesn't work, but how does one perform a substitute on a match in such a situation?
This is just one example of this; another time I've come across this problem is using perl to highlight code syntax on a DOS box using ANSI escape sequences: I would have like to be able to remove the escape sequences that appear within comments or quotes, so something like (off the top of my head):
while(/"(.*?)"/g) { $1 =~ s/\c@\[\d+[a-x]//g; }
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Substitute within a search
by davorg (Chancellor) on Aug 26, 2004 at 11:06 UTC | |
|
Re: Substitute within a search
by tachyon (Chancellor) on Aug 26, 2004 at 11:11 UTC | |
by Anonymous Monk on Aug 26, 2004 at 15:58 UTC | |
|
Re: Substitute within a search
by ccn (Vicar) on Aug 26, 2004 at 10:55 UTC | |
|
Re: Substitute within a search
by bart (Canon) on Aug 26, 2004 at 17:04 UTC |