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!
In reply to Substitute within a search by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |