Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fresh/src/build/deps.ts>regexpEscape

The next-gen web framework.
Extremely Popular
Go to Latest
function regexpEscape
import { regexpEscape } from "https://deno.land/x/fresh@1.4.0/src/build/deps.ts";

Escapes arbitrary text for interpolation into a regexp, such that it will match exactly that text and nothing else.

Examples

Example 1

import { escape } from "https://deno.land/std@0.224.0/regexp/mod.ts";
import { assertEquals, assertMatch, assertNotMatch } from "https://deno.land/std@0.224.0/testing/asserts.ts";

const re = new RegExp(`^${escape(".")}$`, "u");

assertEquals("^\\.$", re.source);
assertMatch(".", re);
assertNotMatch("a", re);

Parameters

str: string