Depending on how frequently you expect this function to be called, caching the RegExp for re-use can help improve performance. I suspect this isn't called that often however (<1000 per doc)