Fixed regexp escaping and added tests