regex - Is there an equivalent to emacs' rx macro in python? -


the rx macro in emacs (see http://www.emacswiki.org/emacs/rx , http://doc.endlessparentheses.com/fun/rx) makes possible specify regular expressions in modular , readable way (at least don't have take care quoting issues). example:

(rx "a" (optional "c") "b") 

results in

"ac?b" 

is there comparable in python?

imo, using lisp syntax define regex not classic usage. how can 1 maintain that? regex language standard; readable everyone; rx not. know omnimark? has pretty verbose syntax. forgotten now…

to can define simple function, eg.:

def optional(regex):     return regex + "?"   def regex(*args):     return "".join(args)   regex = regex("a", optional("b"), "c") print(regex) 

you'll get:

ab?c 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -