in reply to Re: Removing include files
in thread Removing include files

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!