Den fre. 1. maj 2020 kl. 14.20 skrev Tim Hanson <[email protected]>:
> hi, just now I'm debugging a regular expression and trying to understand
> why this:
>
> > (regexp-match-positions #rx"[-+][0-9]+" "-0500")
> '((0 . 5))
>
> works as I expect, whereas this:
>
> > (regexp-match-positions #rx"[-+][0-9]{4}" "-0500")
> #f
>
> doesn't. (My naive opinion is the second expression should return the same
> answer as the first.)
>
The cause of the confusion is that there are several notations for regular
expressions.
Racket supports two types "egrep" and "Perl" ones.
Turns out the repetition syntax with braces {} are only supported in Perl
regular expressions.
Therefore you need to use #px rather than #rx.
The relevant section of the documentation:
[image: image.png]
> Wondering whether I could discover for myself whether this is a known
> issue, I found directly:
>
> https://github.com/racket/racket/search?q=regexp&type=Issues
>
> or perhaps something like this:
>
>
> https://github.com/racket/racket/search?q=regexp+type%3Aissue&unscoped_q=regexp+type%3Aissue
>
> is better, but either way I'm quickly pretty lost in terms of deciding
> whether this relates to a known issue.
>
You need to look at docs.racket-lang.org instead. Then search for "regexp"
or "regular expression".
You will then end up here:
https://docs.racket-lang.org/reference/regexp.html?q=regular%20expression
Also ... if it is any consolation ... you are not the first to be confused
by this.
/Jens Axel
Racket Stories
https://racket-stories.com
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CABefVgx%3D9iTX5op3G4KaJ5Wt2dNDcOVE%2BWV%3DJ3jct_JEWDnEKQ%40mail.gmail.com.