Larry Wall <[EMAIL PROTECTED]> wrote:
:Henry Spencer's original regex routines simply disallowed expressions
:that might be infinite.  We tried relaxing that in Perl 5, and got
:it wrong more than one way.  I'm not actually sure what approach p5
:takes right now, if any.

We detect and warn of repeated empty expressions:
  zen% perl -wle 'print "ok" if "x" =~ /()*/'/'
  ()* matches null string many times in regex; marked by <-- HERE in m/()* <-- 
HERE / at -e line 1.
  ok
  zen% 

For optionally empty expressions, we don't allow them to match emptily
more than once:
  zen% perl -wle 'while ("baa" =~ /((b??)*a)/g) { print "<$1>" }'
  <ba>
  <a>
  zen% 

For optionally empty patterns, we don't allow them to match emptily at
the same location more than once:
  zen% perl -wle 'while ("a" =~ /(a??)/g) { print "<$1>" }'
  <>
  <a>
  <>
  zen% 

This last is achieved by magic on the string to which the pattern is
applied, which can lead to problematic interactions with other magic
(eg tainting) or restoration after local(). In principle it may also
be undesirable if you are parsing a string with a variety of //gc
patterns, and want to allow more than one of them to match an empty
string at the same location.

Hugo

Reply via email to