scoop:scoop.regex:0.1.0
src/extensions.scoop
Selected production source · src/extensions.scoop
1
package scoop.regex3
import scoop.collections.*4
import scoop.text.replace6
/** Compiles this string as a reusable PCRE2 UTF-8 pattern. The caller owns the returned Regex. */7
public 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. */10
public fun String.toRegexOrNone(options: Set<RegexOption> = emptySet()): Regex? {11
try { return Some(Regex(this, options)) }12
catch (error: RegexSyntaxException) { return None }13
}15
internal fun escapeRegexLiteral(literal: String): String =16
"""\Q""" + literal.replace("""\E""", """\E\\E\Q""") + """\E"""