Yea, given that I'm "regex poor", this is a cut/paste job from common/djangoapps/static_replace/__init__.py. Which does some URL rewriting during LMS/CMS rendering. 

Not sure who the original author was.