RegExp
Tools for working with JavaScript regular expressions from the Effect module
namespace. The module exposes the native RegExp constructor, a guard for
narrowing unknown values, and escaping for literal text that will be embedded
in a pattern.
Reach for RegExp when you need to build a regular expression from user or
data-driven text, check whether an unknown value is already a RegExp, or
access the native constructor without leaving the Effect namespace.
Constructors
Exposes the JavaScript regular expression constructor from globalThis.
When to use
Use to construct JavaScript regular expressions through the Effect module namespace.
Signature
declare const RegExp: RegExpConstructorExample
(Creating a regular expression)
import { RegExp } from "effect"
const pattern = new RegExp.RegExp("hello", "i")pattern // => /hello/ipattern.test("Hello World") // => truepattern.test("goodbye") // => falseGuards
Checks whether a value is a RegExp.
When to use
Use to validate unknown input before treating it as a regular expression.
Signature
declare const isRegExp: (input: unknown) => input is RegExpExample
(Checking for regular expressions)
import { RegExp } from "effect"
RegExp.isRegExp(/a/) // => trueRegExp.isRegExp("a") // => falseTransforming
Escapes special characters in a regular expression pattern.
When to use
Use to turn literal text into a safe regular expression pattern fragment.
Signature
declare function escape(string: string): stringExample
(Escaping a pattern string)
import { RegExp } from "effect"
RegExp.escape("a*b") // => "a\\*b"