A regular expression is a sequence of characters defining a search pattern used to find, replace, or validate text. JavaScript relies on the ECMAScript RegExp engine, supporting modern features like Unicode properties and lookbehind assertions. If you are formatting variable lists to camelCase or kebab-case before matching them, convert them with our
Case Converter. Here is how to create a regular expression in JS:
// Literal notation (compiled once when the script is loaded)
const literalRegex = /\b[A-Za-z]+\b/g;
// Constructor function (compiled at runtime, useful for dynamic inputs)
const dynamicRegex = new RegExp("\\b[A-Za-z]+\\b", "g");