Lesson 18 of 55 · javascript
Regular Expressions – `RegExp` & String Methods
Duration: 9 mins
Create a regex:
const emailRE = /^[\w.-]+@[\w.-]+\.\w{2,}$/i;
Common string methods:
match,replace,search,split.
Example: Validate & sanitize input
function sanitize(input){
return input.replace(/[<>"'&]/g, c=>({
'<':'<','>':'>','"':'"',"'":''','&':'&'}[c]));
}
RegExp flags – g (global), i (ignore case), m (multiline), u (unicode), y (sticky).