asRegex

fun String.asRegex(ignoreCase: Boolean = false): Regex

Converts this glob-style pattern string to a Regex; see toPattern for the conversion.

Matching takes O(n * m) steps for an n-character subject and an m-character glob, so a glob taken from user input cannot cause catastrophic backtracking. That bound still grows with both lengths, so limit the length of an untrusted glob and of the text matched against it. A very long glob can also exceed a regex engine's own limits: on Kotlin/JS, V8 throws a SyntaxError on the first match against a glob with around a thousand segments between *s, as it did for around 1,500 *s before.

Return

the compiled Regex

Parameters

ignoreCase

whether to ignore case when matching (default false)