nkiesel
04/04/2022, 10:07 PMfun String.startsWith(
prefix: Regex,
ignoreCase: Boolean = false
): Boolean (and also endsWith)? The ignoreCase parameter would be debatable, but since the String variant has it and it's easy to add to the implementation, I would vote to keep it.ephemient
04/04/2022, 10:17 PMi flagephemient
04/04/2022, 10:18 PMignoreCase this is prefix.matchesAt(string, 0)nkiesel
04/04/2022, 10:21 PMval pattern = if (ignoreCase) Regex(prefix.pattern, RegexOption.IGNORE_CASE) else prefix. Of course, we still have to wrap that in ^ and .*.ephemient
04/04/2022, 10:22 PMephemient
04/04/2022, 10:23 PMignoreCase = false flip it?ephemient
04/04/2022, 10:24 PMmatchesAt you don't need to wrap it in any anchorsnkiesel
04/04/2022, 10:26 PMval pattern = if (ignoreCase) Regex(prefix.pattern, prefix.options + RegexOption.IGNORE_CASE) else prefix. But yes, if the pattern already contains an ?i , then startsWith(pattern, false) would not do the right thing (assuming the in-pattern flags overwrite the outside-of-pattern flags). So perhaps makes more sense to drop the ignoreCase parameter for the `Regex`variant.nkiesel
04/04/2022, 10:26 PMmatchesAt works nicely for startsWith, but not so nice for endsWith.ephemient
04/05/2022, 12:16 AMendsWith on non-regular regexes (as found in basically everything aside from Google RE2)nkiesel
04/05/2022, 12:58 AMfileName.contains(".kt") and filename.contains("Regex("""\.kt""") , and I can write fileName.endsWith(".kt"), so why not also fileName.endsWith(Regex("""\.kt""")) ?