Hyperlinkv0.8.0-beta.28

String

String.matchconsteffect/String.ts:706
(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
searching
Source effect/String.ts:7062 lines
export const match = (regExp: RegExp | string) => (self: string): Option.Option<RegExpMatchArray> =>
  Option.fromNullOr(self.match(regExp))