Engrain by ByteRush

JS.09.01 Junior

Regex basics

Comes up in: JavaScript, Coding

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • literals vs RegExp
  • character classes
  • quantifiers (greedy/lazy)
  • anchors
  • groups and alternation
  • flags g i m s u v y d
  • test, match, matchAll, replace with functions

Words you will know

regular expressionquantifieranchorcapture groupflag

What you will practise

  • 10 small patterns with tests

Interview questions this answers

  • What is the difference between greedy and lazy quantifiers?
  • Why does calling test twice on a global regex give different results?
  • Write a regex to validate an Indian PIN code / a hex colour.