[racket] Destructuring-bind for Regex

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

On Fri, Jan 4, 2013 at 3:37 PM, Galler <lzgaller at optonline.net> wrote:
> Could you possibly briefly elaborate on how the parentheses in the regular
> expression make the destructuring work?

The () in the pattern work exactly like they do in `regexp-match`.

> (regexp-match #px"([\\D]*)([\\d]+\\.[\\d]+)([\\D]*)" "This is a 40.2 Song about Japan")
'("This is a 40.2 Song about Japan" "This is a " "40.2" " Song about Japan")

Scroll down in these docs:
http://docs.racket-lang.org/reference/regexp.html#%28def._%28%28quote._~23~25kernel%29._regexp-match%29%29
to where it says "additional [byte] strings" to see a full description
of how () in regular expressions work.

Sam

Posted on the users mailing list.