5 ms·
Advanced Regular Expressions
- Hexstream 18y agoThe first four of these I wouldn't call "advanced"...
- mncaudill 18y agoWelcome to Smashing Magzine.
- masomenos 18y agonot for full-time programmers, but SM's audience seems to be more designers who may dip into code now and again
- lucumo 18y agoAnd 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.
- emmett 18y agoHow 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...
- stcredzero 18y ago...basic CS concepts... Something which is ironic, and also gets back to basic CS concepts, is that modern scripting languages have added so much power to "Regular Expressions," that they are no longer strictly Regular Expressions. They are no longer equivalent to Finite Automata. "Regular Expressions" in many cases are outright Turing Complete. And so the abuse of our field's terminology continues.
- DEinspanjer 18y agoDFA vs NFA. I thought it was humorous that the most important features of modern regex engines are the things that prevent them from meeting the criteria of the original definition for a regex engine. And of course, with a true DFA regex engine, you'll never suffer from catastrophic backtracking or exponential performance degradation with a bad regex or bad subject string.
- 10ren 18y agoI wish HN had downvotes for articles instead of harsh top comments.
- mcav 18y agoOr if the "flag" button made posts' gravity higher so that they fell to the bottom sooner.
- deleted 18y ago[deleted]
- Poleris 18y agoI 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 18y agoI'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.
- staunch 18y agoCan you make vim use pcre?
- gustavo_duarte 18y agoFrom 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.
- DEinspanjer 18y agoIs 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 18y ago
- viggity 18y agoI'm a big fan of letting named groups being my documentation, instead of using the # comment notation.
- DEinspanjer 18y agoNamed 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.
- Gompers 18y agoConsider 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?
- 10ren 18y agoI hadn't seen recursive regex before (almost a tautology). The operator in the article, "(R?)", isn't in Perl (v5.8.8).
- DEinspanjer 18y agoYeah. PHP syntax. From what I understand, they stuffed it in there mostly to allow easier processing of nested HTML tags and such.
- lucumo 18y agoI 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.
- tjpick 18y agocoz you can't expect anyone using PHP to, you know, write a proper parser...