I'm honoured you're looking at my code, but don't judge me harshly plz. I hope my code comments make sense.
Regex engine has come a long way. There was a time (not that long ago) when split join were faster in most cases.
In the case of fixing broken links (yeah that code is kind of redundant now, but when I remove it you can be sure I'll need it again) I can't work out an elegant regex solution.
I'll elaborate, my split join for broken links does it all in one pass, if I were to use regex I'd have to run multiple regex queries and maybe build regular expressions with regular expressions. At the end of it, I think 'my' regex would be more resource hungry than the method I currently use. You can put that down to my lack of ability with regex, I wont pretend to know things I don't know.
However someone more adept at regex may find the opposite.
There are plenty of parts of linkify that I will change to regex, but the example with broken links will remain as is for a while. It's 100% fool proof and effective, I can't recreate that with regex....maybe one day
Nowadays I often go for regex first, and if I can't do what I need to do I look for other methods. But it wasn't that long ago when I'd use regex as a last resort, funny how things change.
Thanks for the link, that's quite a neat test
Check this one with longer string. Regex is 60% slower for me and this closely applies to my broken link fix routine.
http://jsperf.com/split-join-vs-regex-replace
I think it's all about string length and complexity. Choose based on that imo.
01-Jul-2014 12:49:31
- Last edited on
01-Jul-2014 13:21:22
by
Indecent Act