JS: Regex Functions

By Xah Lee. Date: . Last updated: .

Here is a overview of regex functions.

Best Function to Use

str.matchAll(regex)

Return all occurrences and captures.

str.replaceAll(regex, rep)

Return a new string.

Older Functions

str.search(regex)

Return the index of first char of the match.

str.match(regex)
  • Return all occurrences (if regex has g flag)
  • or return captured groups (if regex has no g flag).
str.replace(regex, rep)

Return a new string.

regex.test(str)

Return true/false.

regex.exec(str)

Return captured groups.

JavaScript. String

JavaScript. Regular Expression