Hyperlinkv0.8.0-beta.28

RegExp

RegExp.escapeconsteffect/RegExp.ts:82
(string: string): string

Escapes special characters in a regular expression pattern.

When to use

Use to turn literal text into a safe regular expression pattern fragment.

Example (Escaping a pattern string)

import { RegExp } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b")
RegExp
Source effect/RegExp.ts:821 lines
export const escape = (string: string): string => string.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&")