Created
August 2, 2021 11:36
-
-
Save carld/93be2ff1d6ded50794e8dd42824385fc to your computer and use it in GitHub Desktop.
Using Scheme's match with regexp in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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