Introduction


We often need to search a file or string for text that match a certain pattern like

  1. Email addresses Ex: user1@primacy.com, super.admin@noveauco.com
  2. A word that begins and ends with the letter ‘d’. Ex: deed, did, depend
  3. Words that are at least 8 characters long

We can specify such patterns with regular expressions. In general, A regular expression is a sequence of characters that specifies a textual pattern. RegExp is the JavaScript class that is used to encapsulate regular expressions. Both the String and RegExp classes define methods that make use of regular expressions to find patterns in text and to search and replace text matching such patterns. The regular expression grammar used by JavaScript is very similar to the ones used elsewhere (like in other programming languages) in computer science. So, anything you learn here will find application elsewhere too.