Replace endsWith with regex for compatibility