[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to grok a complicated regex?
From: |
Rasmus |
Subject: |
Re: How to grok a complicated regex? |
Date: |
Sat, 14 Mar 2015 01:12:42 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> On 2015-03-13, at 23:46, Emanuel Berg <embe8573@student.uu.se> wrote:
>
>> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>>
>>> so I have this monstrosity [note: I know, there are
>>> much worse ones, too!]:
>>>
>>> "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
>>>
>>> (it's in the org-latex--script-size function in
>>> ox-latex.el, if you're curious).
>>>
>>> I'm not asking “what does this match” – I can read
>>> it myself. But it comes with a considerable effort.
>>
>> I dare say most people (even programmers) cannot read
>> that so if you can that's great.
>
> Really? It's not /that/ difficult. You only need enough coffee (or
> tea, in my case), time and motivation.
> You don’t need a genius, or even IQ higher than, say, 90 or so.
Damn. At least I know why I don't understand it now...
To grok REs I sometimes prefer visualize regexps¹ over re-builder. Though
re-builder has the advantage that it can understands \\ out of the box.
You may also find highlight-regexp since it would color the different
parentheses matches.
Here's another project (for your students): adding lookaround to Emacs
regexp /and/ have it merged. It would be *insanely(!)* at times.
—Rasmus
Footnotes:
¹ https://github.com/benma/visual-regexp.el
--
A clever person solves a problem. A wise person avoids it
Message not available