Refactor messy repeated regexp into helper method