Comment

Video: A Dog's-Eye View

417
Charles Johnson3/04/2012 5:50:07 pm PST

And now, the main regular expression that matches web URLs inside arbitrary blocks of text at LGF and turns them into links, videos, tweets, etc. This is just the ‘matching’ part, not the replacement, which actually uses function callbacks to process the matches.

Take a bow, regex. I’m kind of proud of this dense little mess of set theory spaghetti. It’s not perfect, but it’s pretty close.

(?(?=]*>.+?<\/a>)(?:]*>.+?<\/a>)|([^=”\’]?)((?:https?|):\/\/[^<> \n\r]+))