vaibhav.yadav
Tue Jul 30 2024
Cross browser regular expression issue:
Recently I came across a regular expression that would cause the page to crash on iphone Safari browser, the regex was for obscuring email.
Problematic Regex:
Fix:
Lesson: Even a browser can cause browser compatibility issues.
#regex #browserCompatibility #safari #javascript
Recently I came across a regular expression that would cause the page to crash on iphone Safari browser, the regex was for obscuring email.
Problematic Regex:
const obscuredEmail = email.replace(/(?<=.1}).(?=[^@]*@)/g, '*');
Fix:
const obscuredEmail = email.replace(/(.)(?=.*@)/g, (match, p1, offset, string) => offset < string.indexOf('@') - 1 ? '*' : p1);
Lesson: Even a browser can cause browser compatibility issues.
#regex #browserCompatibility #safari #javascript