Skip to main content
Home

@std/regexp@1.0.1
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads1,692/wk
Publisheda year ago (1.0.1)

Utilities for working with RegExp

function escape
escape(str: string): string

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

Examples

Usage

import { escape } from "@std/regexp/escape";
import { assertEquals, assertMatch, assertNotMatch } from "@std/assert";

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

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

Parameters

The string to escape.

Return Type

The escaped string.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/regexp

Import symbol

import { escape } from "@std/regexp/escape";
or

Import directly with a jsr specifier

import { escape } from "jsr:@std/regexp/escape";

Add Package

pnpm i jsr:@std/regexp
or (using pnpm 10.8 or older)
pnpm dlx jsr add @std/regexp

Import symbol

import { escape } from "@std/regexp/escape";

Add Package

yarn add jsr:@std/regexp
or (using Yarn 4.8 or older)
yarn dlx jsr add @std/regexp

Import symbol

import { escape } from "@std/regexp/escape";

Add Package

vlt install jsr:@std/regexp

Import symbol

import { escape } from "@std/regexp/escape";

Add Package

npx jsr add @std/regexp

Import symbol

import { escape } from "@std/regexp/escape";

Add Package

bunx jsr add @std/regexp

Import symbol

import { escape } from "@std/regexp/escape";