[plug] Perl regex question

Mark O'Shea mark at musicalstoat.co.uk
Mon Oct 27 13:12:36 WST 2008


On Mon, Oct 27, 2008 at 02:34:46PM +1100, Daniel Pittman wrote:
> > $line =~ s/<script.*script>//smi ;
> 
> This like makes *absolutely* no sense: you told Perl; the flags
> following the regular expression are 'smi', which means:
> 
>   s => treat this as a single line
>   m => treat this as multiple lines
>   i => ignore case
> 
> You might get more sensible behaviour if you specify *one* of those two
> mutually incompatible options.  In your case, you want '/s', which is an
> instruction to treat it as a single line.
> 
No, they are not in any way mutually incomaptible (although they are
often used in a fashion which is).  The exact meaning are:
/s      Let . match newline and ignore deprecated $* variable.
/m      Let ^ and $ match next to embedded \n.

So while m is rather superluous in this case it is not breaking the
regexp (as demonstrated by trying to use it on the example given in the
OP).

-- 
Mark



More information about the plug mailing list