(string: string): stringEscapes 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 const escape: (string: string) => stringEscapes 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")
escape = (string: stringstring: string): string => string: stringstring.String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and
{@linkcode
replaceValue
}
to the [Symbol.replace] method on
{@linkcode
searchValue
}
. This method is expected to implement its own replacement algorithm.
replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&")