mike mulligan writes:
:From: Hugo <[EMAIL PROTECTED]>
:Sent: Tuesday, September 12, 2000 2:54 PM
:
:> 3. The regexp is matched left to right: first the lookbehind, then 'X',
:> then '[yz]'.
:
:Thanks for the insight - I was stuck in my bad assumption that the optimized
:behavior was the only behavior.
:
:What I am not sure of is whether the "optimization" is ever dangerous.  In
:other words, is there ever a difference in end-result between, doing at each
:point: 1. test look-behind and then test the remainder of the regex, vs 2.
:test the remainder of the regex, and then test the look-behind?

Sometimes it may not be possible at all:
  "axbcxd" =~ /(?<= a(.)b ) c\1d/x;

:I am without a motiviating example, but can anyone see utility in a
:non-greedy look-behind that operates in sense "2" above?   Syntax:
:(?<=pat)?    (?<!pat)?    Currently, a question-mark like this on a
:look-behind makes it optional, defeating the assertion's purpose.  If anyone
:has a good example, I'll take on writing a RFC.

Currently, a question mark like this on a lookbehind is apparently
ignored:
  crypt% ./perl -wle '/(?<=test)?/'
  Quantifier unexpected on zero-length expression before HERE mark in regex 
m/(?<=test)? << HERE / at -e line 1.
  Use of uninitialized value in pattern match (m//) at -e line 1.
  crypt% 

.. but I don't know why, since it could arguably be useful:
  / (?<= (+|-) )? \d+ /x;
  print defined($1) ? "sign: '$1'\n" : "no sign\n";

Note that you can rewrite /(?<=[aeiou])X[yz]/ as /X[yz](?<=[aeiou]..)/
if you really want ...

Hugo

Reply via email to