bhylu.com

Advertisements

JS 2025

Modern additions such as RegExp.escape still need a compatibility decision. Escape user text before incorporating it into a regular expression pattern.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

if (typeof RegExp.escape === "function") {
  const pattern = new RegExp(RegExp.escape("club.plus"));
  console.log(pattern.test("club.plus"));
} else {
  console.log("RegExp.escape is unavailable in this runtime.");
}

What happens

A supported runtime treats the dot as literal text.