The short answer is "no", I can't claim to have gone very far with this problem. I can talk about the nature of the problem a little, though: the trouble with elisp regexps is magnified by the way elisp strings work. There are two separate design decisions that interact very badly with each other.

The regexp design decision: emacs uses an older style of regexps where these are not special characters: "(", "|", ")". If you want them to have what would be their usual meaning in perl regexps, you need to escape them, i.e. "\(", "\|", "\)".

The string design decision: just as with perl, the backslash is used to escape characters to get a special meaning, e.g. "\t" means a tab. Strings are delimited by double-quotes, so if you want a double-quote in a string, you escape it: "\"". And if you want a backslash to just be a backslash, then you double it: "\\".

And in elisp regexps are stored as strings. So if you want to capture some text within double quotes, the regexp might be "\(.*?\)", but the string would be "\"\\(.*?\\)\""

And you can't even follow a simple rule like "double-up all the backwhacks when you put a regexp in a string", because that fails with something like the aforementioned tab code. This is a tab: "\t", but "\\t" is a backslash, followed by a "t".


In reply to Re: [emacs] converting perl regex into elisp regex by doom
in thread [emacs] converting perl regex into elisp regex by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.