Stand Back

 

So I happened to notice that links in posts on the Alter Aeon boards weren't being parsed correctly; lots of false positives and correct urls weren't being linked. So I did what every illogical programmer would do.

So I racked my brain for a few minutes and using the awesome RegExr air app came up with this little gem.

Plain $regex = '#(http://)?((([a-z]+\.[^\W\s])+)([\w\-\.]+/?)+)#';

Three quick things:

  • I use # as a delimiter because escaping slashes is annoying
  • It's extremely sensitive*
  • It works pretty damn well.
One of the problems with regular expressions (amongst the intentional obfuscation that comes with the territory) could be said for pretty much any code: Someone, somewhere already wrote it, and probably better. The trade-off here is that if the problem set is quicker/easier to solve on your own then you're golden, whereas if you have a large problem you could be wasting time solving it yourself.