It is nice.  I'll have to play with this as well.  Thanks again everyone.

On Friday, February 2, 2018 at 5:49:15 PM UTC-6, johnbclements wrote:
>
>
>
> > On Feb 2, 2018, at 3:21 PM, Matthew Butterick <m...@mbtype.com 
> <javascript:>> wrote: 
> > 
> > 
> >> On Feb 2, 2018, at 10:23 AM, 'John Clements' via Racket Users <
> racket...@googlegroups.com <javascript:>> wrote: 
> >> 
> >> This macro gets the names in much closer to the corresponding patterns 
> than matching by index, but it doesn’t actually embed the names into the 
> regexp. 
> > 
> > 
> > If you like keeping the names and patterns together, you could also 
> create an association list of the names and subpatterns, and iterate: 
> > 
> > #lang racket 
> > 
> > (define msg "2018-02-02T11:26:34 someuser some-computername01 
> 233.194.20.110 something broke") 
> > (with-input-from-string msg 
> >  (thunk 
> >    (for/hash ([(name pat) (in-dict '((date . "[-\\dT:]+") 
> >                                      (username . "\\w+") 
> >                                      (hostname . "[-\\w\\d]+") 
> >                                      (ip . "[\\d\\.]+") 
> >                                      (message . ".+")))]) 
> >              (values name (car (regexp-match (pregexp pat) 
> (current-input-port))))))) 
>
> Oh, that’s nice. 
>
> In fact, I’ll tell you what I *really* like about that; it could radically 
> simplify the irritating process of debugging regexps by breaking them in 
> various places to perform a binary search; you could instead provide a nice 
> error message specifying exactly which part of the regexp failed to match. 
>
> One thing to be aware of is that you’d need to make sure that your regexp 
> still works without backtracking. If you broke #px”.*abc” into #px”.*” and 
> #px”abc”, it wouldn’t mean the same thing any more. 
>
> John 
>
> > 
> > 
> > '#hash((message . #" something broke") 
> >       (date . #"2018-02-02T11:26:34") 
> >       (username . #"someuser") 
> >       (hostname . #"some-computername01") 
> >       (ip . #"233.194.20.110")) 
> > 
> > -- 
> > 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...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
>

-- 
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.

Reply via email to