[racket] pregexp vs regexp

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Nov 2 22:15:52 EDT 2010

5 minutes ago, Mark Engelberg wrote:
> As far as I can tell, pregexp functionality is a superset of regexp
> functionality.  Furthermore, the added functionality uses patterns
> that are unlikely to occur by accident in normal regular
> expressions.  So is there any advantage to using regexp over
> pregexp?

No, they're just two slightly different pattern languages.

> Why is there a need for both to coexist in Racket?  What would be
> the downside to removing regexps from the language?

Originally, there was concern over existing patterns that would break
in hard-to-find ways.  I guess that removing `regexp' and the `#rx'
syntax could be used as a brute-force way that makes everyone upgrade
code immediately, but such breakages tend to leave behind useful code
with inactive maintainers.

But I see another advantage for that now -- similar to having all
three `fgrep', `grep', and `egrep' programs on a linux box.  It's just
easy to use the language that fits you more.

In that spirit, I won't even mind some

  #lx"foo" -- literal regexp, same as (regexp (regexp-quote "foo"))

possibly even

  #gx"foo" -- globbing regexp, where you only have "*", "?", and
              "[...]".

but this one can get tricky, since it has many incompatible variants
(eg, linux shells don't match a "." in the beginning unless it's
explicitly in the pattern, and usually "*" doesn't match "/").

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.