Skip to content

Instantly share code, notes, and snippets.

@carld
Created August 2, 2021 11:36
Show Gist options
  • Save carld/93be2ff1d6ded50794e8dd42824385fc to your computer and use it in GitHub Desktop.
Save carld/93be2ff1d6ded50794e8dd42824385fc to your computer and use it in GitHub Desktop.
Using Scheme's match with regexp in Racket
; ISIN, e.g. US0378331005
(define Apple-ISIN "US0378331005")
; ISO6166 International Securities Identification Number (ISIN)
; ISO3166-2 plus National Securities Identifying Number (NSIN)
(match Apple-ISIN
[(regexp #px"^([A-Z]{2})([0-9]{9})([0-9])$" (list _ country NSIN check))
(list country NSIN check)])
(match "http://example.com/foobar"
[(regexp #rx"^([^:]+)://([^/]+)/(.+)$" (list _ protocol hostname path))
(list protocol hostname path)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment