Re: help with regexps
Andreas Bernauer <[email protected]>
| Newsgroups | gmane.lisp.scheme.scsh |
|---|---|
| Message-ID | <[email protected]> |
Hi Michel, Michel Schinz <[email protected]> wrote: > > can anybody help me with this? Why does using tmprx result in an > > error, but using tmp2rx works? > > To me, this looks like a bug, maybe in simplify-regexp, see below. > Some comments on what you wrote, before. Ah, I'm glad (or maybe not?) to hear that. Thank you very much for your helpful comments and diagnostics. > I would suggest that you use the ADT creation functions to create what > you want. Something like this: > > (re-choice (map (lambda (s) (make-re-submatch (re-string s))) > '("yes" "no"))) > > This doesn't need any regexp matching nothing. That looks good to me, thank you for pointing me to this possibility. > I find it a little strange that you want each alternative to be > included in a separate submatch, though. Are you sure that you do not > want to include the whole "or" part in a submatch? If this is the > case, you should use the following instead: > > ---------------------------------------------------------------------- > > (make-re-submatch (re-choice (map re-string '("yes" "no")))) > '#{Re-submatch} > > (regexp->sre ##) > '(submatch (| "yes" "no")) > ---------------------------------------------------------------------- Yes, you are right. I guess finding the right submatch in my solution would have been very difficult and cumbersome. Your solution is far more easier. Thanks again, and thanks to Martin for forwarding this to me, after I messed up my scsh-users subscription. Cheers, -- Andreas.
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBbEXnUZNNpiz9r/gRApgdAJ4m0okDegROfN7pfiyo7H4ZFOeNyQCgmAuL Of5fL8Yt5DowCk/X6pWyubM= =dksP -----END PGP SIGNATURE-----