Dearest Monks,

I must be missing something here, so perhaps soembody can enlighten me. I have written a regular expression, and as far as I can tell, it should work. What I want to do is remove all HTML tags except for <BR>. The following code is not doing what I expect from it.

#!/usr/local/bin/perl -w use strict; my $file = do{local $/; <DATA>}; $file =~ s/ < (?!=BR) [^>]* > //gsmx; print $file; exit; __DATA__ <P ID="pStyle21X0"><SPAN ID="textStyle14">Parthenogenesis . . . . . . +. . . . . . . . 592 <BR>Patents on Life-Forms . . . . . . . . . . . 5 +94 <BR>Paternity Tests . . . . . . . . . . . . . . . 596 <BR>Pedigree + Analysis . . . . . . . . . . . . . 599 <BR>Penetrance . . . . . . . +. . . . . . . . . . 602 <BR>Phenylketonuria (PKU) . . . . . . . . . . + 604 <BR>Plasmids . . . . . . . . . . . . . . . . . . 606 <BR>Polygen +ic Inheritance . . . . . . . . . . . 609 <BR>Polymerase Chain Reactio +n . . . . . . . . 611 <BR>Polyploidy . . . . . . . . . . . . . . . . +. 613 <BR>Population Genetics . . . . . . . . . . . . 617 <BR>Prader- +Willi and Angelman </SPAN>^M </P>^M <P ID="pStyle21X4"><SPAN ID="textStyle14">Syndromes. . . . . . . . . . + . . . . . . 623 <BR>Prenatal Diagnosis . . . . . . . . . . . . . 626 + <BR>Prion Diseases: Kuru and </SPAN>^M </P>^M <P ID="pStyle21X4"><SPAN ID="textStyle14">Creutzfeldt-Jakob Syndrome . + . . . . . 631 <BR>Protein Structure . . . . . . . . . . . . . 634 <B +R>Protein Synthesis. . . . . . . . . . . . . . 638 <BR>Proteomics . . + . . . . . . . . . . . . . . . 643 </SPAN>^M ^M <SPAN ID="textStyle14">Pseudogenes . . . . . . . . . . . . . . . . 646 + <BR>Pseudohermaphrodites . . . . . . . . . . 648 <BR>Punctuated Equi +librium. . . . . . . . . . 650 </SPAN>^M </P>^M

I would expect that this would print out the data with only "BR" tags remaining.... however this is what I get:

Parthenogenesis . . . . . . . . . . . . . . 592 Patents on Life-Forms +. . . . . . . . . . . 594 Paternity Tests . . . . . . . . . . . . . . + . 596 Pedigree Analysis . . . . . . . . . . . . . 599 Penetrance . . + . . . . . . . . . . . . . . . 602 Phenylketonuria (PKU) . . . . . . +. . . . 604 Plasmids . . . . . . . . . . . . . . . . . . 606 Polygeni +c Inheritance . . . . . . . . . . . 609 Polymerase Chain Reaction . . + . . . . . . 611 Polyploidy . . . . . . . . . . . . . . . . . 613 Pop +ulation Genetics . . . . . . . . . . . . 617 Prader-Willi and Angelma +n ^M ^M Syndromes. . . . . . . . . . . . . . . . 623 Prenatal Diagnosis . . . +. . . . . . . . . . 626 Prion Diseases: Kuru and ^M ^M Creutzfeldt-Jakob Syndrome . . . . . . 631 Protein Structure . . . . . + . . . . . . . . 634 Protein Synthesis. . . . . . . . . . . . . . 638 + Proteomics . . . . . . . . . . . . . . . . . 643 ^M ^M Pseudogenes . . . . . . . . . . . . . . . . 646 Pseudohermaphrodites . + . . . . . . . . . 648 Punctuated Equilibrium. . . . . . . . . . 650 +^M ^M

What am I missing? Should not the (?!=BR) cause the regex to not match the <BR> tags?

Any Wisdom would be mutch appriciated.

May the Force be with you

In reply to Forward look ahead assertion problems by JediWizard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.