I've been regretably away from my mistress, Perl, for a while, and now I thougt I would whip out a short script to do some global text edits on a bunch of html files.

I was able to come up with something but it raised a question. Can you write a regex that matches all strings not containing the substring string 'foo'?

Here are my particular details...

I have a bunch of html files with blank images as spacers, but these don't always render right in mozilla unless they have a 'style="display:block"' attribute. Some designers were good about adding these and some were not, leading to fles whith a mix of haves and have not image tags. So what I thought was, "Find all the image tags that don't have a 'style="display:block"' attribute and add it. But how would you right that? I came up with:
#!/usr/bin/perl while(<DATA>) { if(m/<img\s+src="\/images\/blank.gif"/ && !m/display:block/) { print; s|(<img\s+src="/images/blank.gif".*?)>|$1 style="display:block +">|; print; } } __DATA__ <img src="/images/blank.gif" border="0"> <img src="/images/blank.gif" border="0" style="display:block" > <img src="/images/blank.gif" border="0">
this works, but it seems that I should be able to do this in a single s/// instead 2 matches and a swap. Thanks for taking the time to look at my post. I did a search for docs before posting but I could certainly have missed something. Pointers to pertinent nodes are appreciated.

Ira,


In reply to How do I write a regex for 'does not contain' a string. by IraTarball

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.