I have been working on a a perl script for awhile and everything is going well other then I am constantly confused by how the regexs work.

It is my understanding that a line like string =~ s/"//; should replace all occurrences of " with nothing. However the strings it acts on usually have 2 ", and to eliminate both of them I have resorted to repeating the line.

Another series of regexs are not working as I expect them to either.

foreach (@content) { if ($content[$count] =~ /entertainment_headlines.gif/ or $content[ +$count] =~ /Chewy Headline Snacks/ or $content[$count] =~ /FEATURED INK/ or $content[$count] =~ / +StatCounter/ or $content[$count] =~ /NW Insider/ or $content[$count] =~ /twitterbadge22/){ splice(@content, $count, 1); } $count++; }
I believe this should elimiate array entries that contain these strings, but it doent seem two work msot of the time. It doesnt eliminate the array entry that ends with
</table> </div> <div class="moduletable"> <h3> FEATURED INK </h3> <table class="contentpaneopen">

or the one that contains

<!-- Start of StatCounter Code --> <br /><script type="text/javascript"> var sc_project=3028426; var sc_invisible=0; var sc_partition=32; var sc_security="0f2a9250"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter +/counter_xhtml.js"></script><noscript><div class="statcounter"><a cla +ss="statcounter" href="http://www.statcounter.com/"><img class="statc +ounter" src="http://c33.statcounter.com/3028426/0/0f2a9250/0/" alt="f +ree html hit counter" /></a></div></noscript> <br /><!-- End of StatCounter Code -->

And while I am at it I also want to elimiate all newline characters from a string and assumed that $string =~ s/\n//; would do that but it doesnt seem to work at all.

Clearly I am not getting something about regexs. I have read up on them and its still not clear to me what I'm doing wrong. Any help or generally some negative reinforcement would be greatly appreciated.


In reply to Regex Confusion by Kelly22

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.