It sounds like you're working through some tricky regex concepts, and I can see where the confusion might be coming from. Let’s break it down.
~k - Discretionary Line Break is used as a discretionary line break in certain environments, particularly for typesetting. In simple terms, it's a hint for where the line can be split, but the break isn't enforced unless necessary (like at the end of a line). It’s not something you'll use often in regular expressions, but it can come in handy when formatting text that might need soft breaks..
Say for a really really long URL - you might want to put in a discretionary line break so that it breaks at logical points - and if the text reflows/changes size/tracking/scaling etc that the Line break appears/disappears as you adjust instead of breaking at illogical places. It can be used for many instances, not just URLs.
\K is a relatively lesser-known regex feature, sometimes referred to as a "reset" or "keep" marker. It basically lets you reset the match everything before \K is "forgotten," and what follows it is what gets captured in the match. It’s particularly useful for situations where you want to exclude certain characters from the final match while still working with them for the purposes of the pattern.
For example, if you're trying to match a string but exclude a specific part of it, \K helps you reset the starting point.
Here’s an example:
abc\Kdef
This matches "def" but only returns "def" because "abc" is reset by \K.
The (?<=\d) vs (?<=\d+) issue
This is a tricky one. You’re running into a common regex behaviour involving lookbehinds.
(?<=\d) works because it checks if there's a digit just before your match (i.e., a "positive lookbehind" for a single digit).
(?<=\d+) doesn't work because lookbehinds in most engines (including InDesign's) require a fixed-length pattern. The \d+ part (any number of digits) is variable-length, and regex engines can’t handle that in a lookbehind.
This is where \K could help, as it allows you to work around the limitations of variable-length lookbehinds by allowing the reset to happen after you've matched something, while still keeping the important part.
You could try play with InDesign regex expressions
So this
(?<=\d\b).+
Could do the same as
\d+\K.+
But lookbehinds and lookaheads with a + are not available in most Regex as explained earlier.