Package: effect
Module: String
Matches a string against a pattern safely and returns Option.some with the match
array, or Option.none when the pattern does not match.
Example (Matching regular expressions)
import { Option, pipe, String } from "effect"
const match = pipe("hello", String.match(/l+/))
if (Option.isSome(match)) {
console.log(`${match.value[0]}@${match.value.index}`) // "ll@2"
}
console.log(Option.isNone(pipe("hello", String.match(/x/)))) // true
Signature
declare const match: (regExp: RegExp | string) => (self: string) => Option.Option<RegExpMatchArray>
Since v2.0.0