I need to place <para> ... </para> tags around every line of a file, except when the line happens to contain a <title> tag. The code I've tried is:s/(?!<title>(.*?)\n/<para>$1<\/para>/isg;
If I have that right, you don't really need negative look-ahead. You just need to have a conditional statement that controls whether or not the regex substitution applies -- in fact, you don't really need a regex substitution at all.
Since you say that the file is composed of lines, and the tags are supposed to be added on every line (except any with a "title" tag), it will be easier to handle the data line-by-line, rather than in a single "slurped" scalar:
(update: added ^ anchor to the regex, because the question mentioned looking for that tag at the start of a line)while (<>) { if ( not /^<title>/ ) { chomp; $_ = "<para>" . $_ . "</para>\n"; } print; }
In reply to Re: Negative look ahead
by graff
in thread Negative look ahead
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |