Scoop API

scoop:scoop.regex:0.1.0

src/extensions.scoop

Selected production source · src/extensions.scoop

1package scoop.regex
3import scoop.collections.*
4import scoop.text.replace
6/** Compiles this string as a reusable PCRE2 UTF-8 pattern. The caller owns the returned Regex. */
7public fun String.toRegex(options: Set<RegexOption> = emptySet()): Regex = Regex(this, options)
9/** Returns None only for pattern syntax errors; allocation and unrelated failures still propagate. */
10public fun String.toRegexOrNone(options: Set<RegexOption> = emptySet()): Regex? {
11 try { return Some(Regex(this, options)) }
12 catch (error: RegexSyntaxException) { return None }
15internal fun escapeRegexLiteral(literal: String): String =
16 """\Q""" + literal.replace("""\E""", """\E\\E\Q""") + """\E"""