No, regexp-match is designed to return first the entire match followed by
the matched parenthesized expressions.
You can always write a wrapper that returns the parenthesized expressions
if you want:

#lang racket

(define (regexp-match-sub-matches rx str)
  (cdr (or (regexp-match rx str) '(a . #f))))

(regexp-match-sub-matches #rx"\"(.*)" "a\"b") ; => '("b")


Laurent


On Fri, May 10, 2013 at 5:27 PM, Don Green <[email protected]>wrote:

> Regexp question:
> Is there a way using regexp only to return a list with a single element?
> I could use a Racket list function such as caar to return the second
> element but I am wondering if there is a way to do this using regexp only.
>
> For example this regexp-match function generates the "b" that I want but
> it is the second element in the list.  It would be ideal, from my
> perspective, if that was all it generated. Is there a way to write the
> regexp-match expression so that '("b") is output?
>
> I get this:
> (regexp-match #rx"\"(.*)" "a\"b") ; => '("\"b" "b")
>
> I'd prefer:
> (regexp...                      "a\"b" ) ; => '("b")
>
> Thanks.
> Don Green
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to