Using regex match instead of endsWith for better browser compatibility