

Advanced Regular Expressions - pchristensen
http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/

======
emmett
How did this get to the top of HN? It seems like a boring blogospam rehash of
a bunch of very basic CS concepts, not even well written...

~~~
10ren
I wish HN had downvotes for articles instead of harsh top comments.

~~~
mcav
Or if the "flag" button made posts' gravity higher so that they fell to the
bottom sooner.

------
Gompers
_Consider the word ‘smashing’. Using the above regular expression, the regex
engine will first try to match the pattern ‘hi’ in ‘smashing’. It will not
find a match._

... what?

------
Poleris
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?

~~~
gustavo_duarte
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.

~~~
DEinspanjer
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. :)

~~~
gustavo_duarte
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.

------
10ren
I hadn't seen recursive regex before ( _almost_ a tautology). The operator in
the article, "(R?)", isn't in Perl (v5.8.8).

~~~
DEinspanjer
Yeah. PHP syntax. From what I understand, they stuffed it in there mostly to
allow easier processing of nested HTML tags and such.

~~~
lucumo
I did some experimenting with recursive regexes after reading this article. I
hadn't heard of it before and it sounded like an interesting concept.

However, captures in the recursion can't be retrieved after it gets returned.
This may not be surprising, but it does reduce the power of recursion
somewhat.

------
Hexstream
The first four of these I wouldn't call "advanced"...

~~~
lucumo
And yet I was pleasantly surprised. I'm quite used to finding "advanced"
articles on various programmic topics and finding that everything said in them
is so basic that I can't learn even the smallest piece of information from it.

This one still had some quite interesting pieces of information that I hadn't
heard of or hadn't studied in detail yet.

------
viggity
I'm a big fan of letting named groups being my documentation, instead of using
the # comment notation.

~~~
DEinspanjer
Named groups have their use and are nice when the language supports them.
There is a lot to be said for the (?xi) flags to allow a complicated regex to
be indented and commented usefully.

