The poster mentioned that the word at the end *may* be there, and it may not be; so probably you want that quantifier to be a * (zero or more) not a + (one or more).

Also, underscores count as word characters (in the default locale on my systems (US English) at least), so that regex to get rid of those includes should be:

s|<!--#include virtual="/global_nav\w*\.ssi)"-->||g;

If you're not *sure* it's all *word* characters, then perhaps change that \w* to a [^.]*?, but that's probably unnecessary.

However, I think those are the ones the poster wants to keep; all others are to be deleted. (UPDATE oh, that's just wrong. I reread the post. Sorry AidanLee ... but my question still stands).

I don't have a neat solution for this. I tried

s|<!--#include virtual="(?!/global_nav\w*\.ssi" -->||g;

(using zero-width negative lookahead, i.e. "anything that doesn't match this pattern") but it didn't work, and I can't figure out how to fix it. Something's not working right in my brain today, but a two-step thing like this might suffice:

foreach (@line_in body) { # quasi-pseudocode if (|(<!--#include virtual="([^"]+)"-->|) { #$1 contains the whole match, # $2 what's in between the quotes # so delete $1 unless $2 matches the pattern s/$1// unless $2 =~ m|/global_nav\w*\.ssi|; } }

HTH ... and if anybody can tell me where my thinking's leading me down with my first stab, do tell!


In reply to Re: Re: Removing include files by arturo
in thread Removing include files by Anonymous Monk

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.