On Mar 17, 2016, at 2:05 PM, Andrew Gwozdziewycz <apg...@gmail.com> wrote: > I am imagining an API that utilizes SCSH style regexes but allows you to do > something like this (fictional): > > (define-values (area prefix line) (sre-match (: (= digits 3) (_? "-") (= > digits 3) (_? "-") (= digits 3))))
Racket's `match` is not far from this. In fact maybe I shouldn't be thinking in terms of hacking regexps, but rather making a new match expander. For instance, you can destructure a list like so: (match '("foo" "-42.3" "bar") [(list a (? string->number b) c) 'yay] [else 'boo]) So it would extend logically to this pseudocode: (match "foo-42.3bar" [(string-append a (? string->number b) c) 'yay] [else 'boo]) On Mar 17, 2016, at 2:35 PM, Daniel Prager <daniel.a.pra...@gmail.com> wrote: > Do you want the leftmost, longest substring matching the predicate? > Sometimes, but that's not hard to figure out. More often, I want to match multiple predicates within one string. #lang racket (define (substring/p pred str) (for*/first ([strlen (in-value (string-length str))] [left-pos (in-range strlen)] [right-pos (in-range strlen left-pos -1)] [this-substring (in-value (substring str left-pos right-pos))] #:when (pred this-substring)) this-substring)) (equal? (substring/p string->number "foo-46.3bar12789") "-46.3") -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.