toPattern
Converts a glob-style pattern (using * and ? wildcards) to a regex pattern string.
Extension property on String. * matches any run of characters other than line terminators, as .* does, and ? becomes .. Every other character matches itself, with the regex metacharacters \ ^ $ . | + ( ) [ ] { } escaped. The result is anchored with ^ and $.
A run of *s is written once, and a glob with no segment between two *s converts as before ("a*b" becomes ^a.*b$). Each segment between two *s is matched where it first occurs, and a failed match never comes back to try a later occurrence: for a glob, the first occurrence is always the right one. On the JVM, Native and Wasm the segment becomes an atomic group ("*a?b*" becomes ^(?>.*?a.b).*$). JavaScript's RegExp has no atomic groups, so on Kotlin/JS it becomes an atomic lookahead followed by a back reference that consumes what it matched (^(?=(.*?a.b))\1.*$), and each such segment is a capturing group, numbered from 1, that holds the text from the end of the previous segment through the end of this one.
Matching an n-character subject against an m-character glob therefore takes O(n * m) steps, where writing .* for each * took about n^k steps to fail for a glob with k *s.