[racket] Some design "whys" of regexps in Racket

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Jun 3 22:36:59 EDT 2011

2011/6/3 Rodolfo Carvalho <rhcarvalho at gmail.com>:
> Hello,
> I'm curious about 2 design decisions made:
> 1) Why do I have to escape things like "\d{2}" -> "\\d{2}"?

Because "\d" is the same as "d", because you're escaping the character
#\d. But, the syntax for the regular expression is #\backslash #\d, so
you need to get a backslash in there, which is otherwise a control
character, so you need to escape it.

> 2) Why there are two kinds of regexps, #rx and #px?
> #rx"\\d{2}" doesn't work because the curly braces are part of just pregexps
> grammar...

#px is more powerful than #rx, but that power costs. Most regexps can
get by with what #rx has.


> []'s
> Rodolfo Carvalho
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.