in reply to Unexpected behaviour of /x Regexp modifier?

Ah. That nicety of the included space had escaped me. For some reason I had imagined that Perl would dwim and not apply the /x within the captures. D'oh. Thank you, as ever!

This signature is but a foretaste of The Great Signature to come
  • Comment on Re: Unexpected behaviour of /x Regexp modifier?

Replies are listed 'Best First'.
Re^2: Unexpected behaviour of /x Regexp modifier?
by codeacrobat (Chaplain) on Mar 16, 2009 at 20:27 UTC
    Hi, you can easily capture spaces literally in \Q ... \E expressions, they are unaffected by /x, see http://perldoc.perl.org/perlre.html#Modifiers
    perl -le ' print scalar localtime; $_=scalar localtime; /^\QMon Mar \E (\d+) \s (\d+) : (\d+) : (\d+) \s (\d+)/x; print "$1 $2-$3-$4 $5" ' Mon Mar 16 21:22:30 2009 16 21-19-13 2009

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

      Another way to do that is to turn x off for part of the pattern, either by toggling it, / ... (?-x)Mon Mar (?x) ... /x, or by localising the effect inside parentheses, / ... (?-x:Mon Mar ) ... /x. The technique can also be used for the i flag and, I think though I've never tried it, for s and m as well.

      I hope this is of interest.

      Cheers,

      JohnGG

Re^2: Unexpected behaviour of /x Regexp modifier?
by ysth (Canon) on Mar 17, 2009 at 01:59 UTC