Useful Regex Flags and String Methods

Example1 - Inline 
Example2 - Define separately
const patternToMatch = new RegExp("puppy");
Simple regex pattern searching for one word or character
Regex global flag returns all matches
An example of the regex flag with the global and case insensitive flag
Regex with brackets matches all characters inside the brackets
Regex caret key example matching all opposites
Regex to match a number
Regex matching 2 digit numbers
Regex to replace a string
Regex to test whether the passed work exists in the string
A list of common regex special characters



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cristian Cedacero

Cristian Cedacero

Full Stack Developer — Runner — NYC