in reply to [emacs] converting perl regex into elisp regex
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".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [emacs] converting perl regex into elisp regex
by doom (Deacon) on Sep 18, 2009 at 02:04 UTC | |
|
Re^2: [emacs] converting perl regex into elisp regex
by LanX (Saint) on Sep 18, 2009 at 02:53 UTC | |
by LanX (Saint) on Sep 18, 2009 at 03:30 UTC | |
by u65 (Chaplain) on Jul 27, 2016 at 15:08 UTC | |
by LanX (Saint) on Jul 27, 2016 at 15:40 UTC |