Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Emacs' "old" regexp syntax
1 point by mtoledo on July 15, 2008 | hide | past | favorite | 2 comments
I've been using emacs recently, and I had a bunch of code editing I needed done. Figured I'd use emacs for the regex heavy lifting.

I failed miserably. My capturing groups didn't work. Then my digit character classes didn't work either. I was stunned.. what was I doing wrong?

Then I stumbled on Steve Yegge's emacs reg-exp post, where explains all of those limitations:

    *  You have to escape the (, ), {, }, and | metacharacters. That is, they're not metacharacters by default — without the backslash, they match themselves.

    * There's no '\d' shortcut for the [0-9] character class.

    * There are no lookahead or lookbehind assertions.

    * There are no direct equivalents for Perl's {n}?, {n,}?, {n,m}?, /i, /m, /s, /x, \G, or (?# ...) constructs.

So, one of his examples matches: \(public Relative \)\(\w\)\(\w+\)

while usually you'd match: (public Relative)(\w)(\w+)

I really must say that I was surprised that, being such a killer editor, we as a community never got round to implementing a modern regexp syntax for emacs.

Is it that hard? Do many people miss this? ..or you eventually get used to the old syntax and skipping everything?

http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-22.html



see rx.el in (i think) the emacs-lisp directory


Will do. Thanks for the tip.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: