It might be worth moving this outside the function.  That way the regex won't need to be compiled on every call.