[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ugly regexps

From: Stefan Kangas
Subject: Re: Ugly regexps
Date: Wed, 3 Mar 2021 12:46:47 -0600

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Why would someone find rx unpalatable?
> Maybe just because of habit, but I think the main downside of `rx` is
> that it's very verbose, which ends up hiding the "text".  For example in
>     (rx "(def" (or "macro" "un" "subst")))
> I find the `or` to get a bit in the way of my visual cortex recognizing
> the "defmacro" pattern above.

It is also just another thing to learn.

If you're just doing some basic ELisp functions for your personal
editing you might not want to spend time parsing the docstring of `rx'
just to say "^(foo|bar)".  This applies also if you're just writing some
small package that just needs a regexp or two.

Also, `rx' does not translate to most other languages.  So if you are
learning regexps for the first time or are still struggling with them,
you will IMO probably be better off staying away from `rx' for a while.
Note also that you can't use `rx' syntax in `query-replace-regexp'.

I am not surprised that we don't see `rx' used more, even if I would
certainly wish that wasn't the case.  Especially in our own sources.
(It's too bad that we don't use it in our preloaded code, for example.)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]