Lesson 18 of 55
javascriptRegular Expressions – `RegExp` & String Methods
9 mins
Course progress33%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 18 of 55
javascript9 mins
Keep these ideas in mind as you work through the lesson.
Create a regex:
const emailRE = /^[\w.-]+@[\w.-]+\.\w{2,}$/i;
Common string methods:
match, replace, search, split.function sanitize(input){
return input.replace(/[<>"'&]/g, c=>({
'<':'<','>':'>','"':'"',"'":''','&':'&'}[c]));
}
RegExp flags – g (global), i (ignore case), m (multiline), u (unicode), y (sticky).