Re:RegExpBuilder – Create regular expressions using chained ...
by skymt on Wednesday February 11, 2015 @02:09PM
(#9034886)
Alternate representations of regexes aren't necessarily a crutch to avoid learning the normal syntax. S-expressions in particular could be useful for runtime manipulation or generation of patterns without the bother of string mangling. (I can't think of a reason to do so off-hand, but it's a nifty capability.)
[ Parent
| on HN ]
Re:RegExpBuilder – Create regular expressions using chained ...
by to3m on Wednesday February 11, 2015 @03:07PM
(#9035380)
Here's an example of this kind of thing from some emacs lisp I wrote (which I hope survived the transition to the HN comment box):
(setq imenu-generic-expression
(let ((ident '(1+ (any "A-Za-z0-9_"))))
`(("plugin" ,(rx line-start
(0+ space) "plugin"
(1+ space) (eval ident)
(1+ space) (group (eval ident)))
1))))
Of course, you can do this with string concatenation, but I think this syntax makes it clearer what's going on.