(regExp: RegExp | string): (
self: string
) => Option.Option<RegExpMatchArray>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/)))) // truesearching
Source effect/String.ts:7062 lines
export const const match: (
regExp: RegExp | string
) => (
self: string
) => Option.Option<RegExpMatchArray>
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
match = (regExp: string | RegExpregExp: RegExp | string) => (self: stringself: string): import OptionOption.type Option.Option = /*unresolved*/ anyOption<RegExpMatchArray> =>
import OptionOption.fromNullOr(self: stringself.String.match(regexp: string | RegExp): RegExpMatchArray | null (+1 overload)Matches a string with a regular expression, and returns an array containing the results of that search.
match(regExp: string | RegExpregExp))