News for hackers. Stuff that matters.
Re:Advanced Regular Expressions by Poleris on Thursday May 07, 2009 @12:50PM (#598223)
I find when I move across languages (which happens frequently) or even tools (like grep), regexp implementation often differs enough to throw me off and introduce subtle bugs.

Is there a page that shows a mapping between different implementations of regular expressions and which languages and applications they're used in? Is there a better way to figure these things out than hunt for documentation every time?

Re:Advanced Regular Expressions by DEinspanjer on Thursday May 07, 2009 @02:10PM (#598380)
A tool I find useful enough to warrant purchasing and running in a VM or Wine is RegexBuddy. It is great for debugging / optimizing regexes and supports several different language flavors. Still waiting for Vim and PHP flavors though. :) It allows you to generate code snippits in several languages that use the regex you constructed, and will assist you in performing cross-language translations.
Re:Advanced Regular Expressions by gustavo_duarte on Thursday May 07, 2009 @01:15PM (#598268)
I've written an automated tool to convert Vim-style regexes to Perl-style. This is kind of a dramatic case as the dialect is very different, but it was a fun thing to write.
Re:Advanced Regular Expressions by DEinspanjer on Thursday May 07, 2009 @02:12PM (#598386)
Is it bi-directional? Is it on the vim.org website somewhere? I find Vim's escape heavy syntax cumbersome and I frequently wish I could write a quick Perl syntax regex and convert it to Vim.

Of course, Vim is one of the few regex engines to support variable width negative look-behinds, so I guess that counts for something. :)

Re:Advanced Regular Expressions by gustavo_duarte on Thursday May 07, 2009 @02:19PM (#598397)
Only Vim -> Perl is fully fleshed out right now. Doing it the other way would be fairly easy though because so much would be reused. Also, with the Vim regexes I had to worry about magicness and so on, the Perl stuff would parse easier.

It's not in Vim.org. I had the code floating around with an MIT license, but it's offline right now. I thought about building a page where you could do the translation (I figured Perl -> Vim is what people would want more) or just use a simple GET request from other code.

Maybe I should do the Perl -> Vim bit and make it available.

Re:Advanced Regular Expressions by staunch on Thursday May 07, 2009 @02:01PM (#598359)
Can you make vim use pcre?
Re:Advanced Regular Expressions by gustavo_duarte on Thursday May 07, 2009 @02:07PM (#598372)
From my look in the Vim sources, it would be tons of work to truly make it use pcre internally.

But I think it wouldn't be hard to do a plugin that translates a pcre into a Vim regex, allowing you to search or replace using pcres.

My code though is not integrated with Vim, it takes a free floating regex and converts it. I used it to convert all the regexes in Vim syntax files and build a syntax highlighter. It was a silly project, just for fun.

Re:Advanced Regular Expressions by 0xdefec8 on Thursday May 07, 2009 @01:40PM (#598329)
indeed. grep -P is your friend. (except older grep versions seem to segfault on me constantly with various -P regexes)
Re:Advanced Regular Expressions by zouhair on Thursday May 07, 2009 @01:40PM (#598328)
sudo aptitude install txt2regex