Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

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=>({
    '<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;','&':'&amp;'}[c]));
}

RegExp flags – g (global), i (ignore case), m (multiline), u (unicode), y (sticky).

Previous: Working with Dates – `Date` object & IntlNext: Array Methods – map, filter, reduce, find, some, every