JavaScript: the Web Programming Language
JavaScript Regular Expressions
Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec()
and test()
methods of RegExp
, and with the match()
, matchAll()
, replace()
, replaceAll()
, search()
, and split()
methods of String
.
To learn more, click to read a thorough discussion of JavaScript Regular Expressions
A regular expression is typically created as a literal by enclosing a pattern in forward slashes (/): Regular expressions can also be created with the They have no runtime differences, although they may have implications on performance, static analyzability, and authoring ergonomic issues with escaping characters.Creating regular expressions
const regex1 = /ab+c/g;
RegExp()
constructor:const regex2 = new RegExp("ab+c", "g");