[racket] Destructuring-bind for Regex

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Fri Jan 4 15:19:51 EST 2013

How about this:

(match "This is a 40.2 Song about Japan"
  [(regexp #px"([\\D]*)([\\d]+\\.[\\d]+)([\\D]*)" (list _ x y z))
   (list x y z)])
;; produces
'("This is a " "40.2" " Song about Japan")

The `_` is ignoring the first result of `regexp-match`, which is the full match.

Sam

On Fri, Jan 4, 2013 at 2:50 PM, Galler <lzgaller at optonline.net> wrote:
> Hello,
>
> Is there a destructuring-bind for regular expressions?
>
> Something along the lines of the purely fictional function
> "with-destructuring-regex", below:
>
> (with-destructuring-regex ([(list #px"[\\D]*"  #px"[\\d]+\\.[\\d]+"
> #px"[\\D]*") "This is a 40.2 Song about Japan" (x y z)])
>                          (values x y z))
>
> ;->
> ;"This is a "
> ;"40.2"
> ;"Song about Japan"
>
> This seems very much like something Danny would have implemented at some
> point in time.
>
>  If the answer is no, I'll just go ahead and code it and share results, if
> of interest.
>
> Thanks much.
>
> Zack
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Posted on the users mailing list.