JavaScript Regular expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • let regex = /pattern/[flags]
  • let regex = new RegExp('pattern', [flags])
  • let ismatch = regex.test('text')
  • let results = regex.exec('text')

Parameters

FlagsDetails
gglobal. All matches (don't return on the first match).
mmulti-line. Causes ^ & $ to match the begin/end of each line (not only begin/end of string).
iinsensitive. Case insensitive match (ignores case of [a-zA-Z]).
uunicode : Pattern strings are treated as UTF-16. Also causes escape sequences to match Unicode characters.
ysticky: matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes).

Remarks

The RegExp object is only as useful as your knowledge of Regular Expressions is strong. See here for an introductory primer, or see MDN for a more in-depth explanation.



Got any JavaScript Question?