negative lookahead problem
[email protected] (allan) Fri, 10 Aug 2001 00:01:25 +0200
| Newsgroups | perl.macperl.anyperl |
|---|---|
| Message-ID | <[email protected]> |
hi i want to do a global replace om a search string _unless_ the string is encapsulated in <script></script> tags. i have a file that looks like this <script> type=text1 type=text2 </script> type=text3 type=text4 <script> type=text5 type=text6 </script> type=text7 type=text8 and a program that looks like this. apparenly somthing is wrong as it only does a replace on the last types (text7 and text8) when it should also replace text3 and text4. maybe the whole approach is wrong? allan #!perl -w open FILE, "file.txt"; local $/; $_ = <FILE>; s/(?!<script[^>]*>.*) #as long a string doesnt start with <script ...> and ([^\s"'<>%()]+=) #string does match one or more characters which are not in this class and is followed by =, and ([^\s"'<>]+) #string match one or more characters which are not in this class and (?!.*<\/script>) #as long as string doesnt end with <...script> /$1"$2"/igsx; print;