Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Regarding regular expressions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pixel <pixel@m...>
Subject: Re: [Caml-list] Regarding regular expressions
Jerome Vouillon <vouillon@pps.jussieu.fr> writes:

[...]

> > So, nearly half of all perl scripts on CPAN that use regular expressions
> > make use of the backreference feature.  IMO this argues strongly in
> > favor of supporting backreferences in C++.  (Backreferences can only be
> > handled by a backtracking NFA engine, IIRC.)
> 
> What he means by backreference is a way to refer to a submatch.  For
> instance, with the regular expression "^([^ ]*) *([^ ]*)", the
> backreference "$1" will refer to the substring matched by the first
> parenthesed subexpression "([^ ]*)".  As long as the references do not
> occur in the regular expression itself, they can be handled perfectly
> well with a DFA engine.  So, the numbers above do not prove anything.

agreed.

Here are the numbers I get (only scanning perl 5.8.0, not CPAN):

% cd /usr/lib/perl5/5.8.0
% find -name "*.p[lm]" | xargs perl -ne 'print "$ARGV: $_" if /[=!]~\s*[^ty ]/' | wc -l
   2640
% find -name "*.p[lm]" | xargs perl -ne 'print "$ARGV: $_" if /[=!]~\s*[^ty ]/' | perl -ne 'print if /\\[1-9]\D/' | wc -l
      3
% find -name "*.p[lm]" | xargs perl -ne 'print "$ARGV: $_" if /[=!]~\s*[^ty ]/' | perl -ne 'print if /\\[1-9]\D/'
./ExtUtils/MM_Win32.pm:      while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
./Pod/Text/Overstrike.pm:     $text =~ s/(.)[\b]\1/$1/g;
./Test.pm:          (undef, $regex) = ($expected =~ m,^ m([^\w\s]) (.+) \1 $,sx)) {

> - how often are backreferences used within a pattern?

I get 3 / 2640 = 0.1%
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners