There is no direct equivalent . However, you can always rewrite such patterns with capture groups.
If you take a closer look at the \K operator and its limitations, you will see that you can replace this pattern with capture groups.
See rexegg.com \K link :
In the middle of the pattern, \K says "reset the start of the reported match with this point." Everything that was matched before \K is not reported, a bit like lookbehind.
The key difference between \K and lookbehind is that in PCRE, lookbehind does not allow the use of quantifiers: the length of what you are looking for must be fixed. On the other hand, \K can be dropped anywhere in the pattern, so you can freely use any quantifiers up to \K
However , all this means that the pattern before \K is still a consuming pattern, i.e. the regex mechanism adds matching text to the match value and advances its index when the pattern matches, and \K only removes matching text from the match, keeping the index where it is. This means that \K no better than capturing groups.
So, a value\s*=\s*\K\d+ PCRE / Onigmo will translate this Java code:
String s = "Min value = 5000 km"; Matcher m = Pattern.compile("value\\s*=\\s*(\\d+)").matcher(s); if(m.find()) { System.out.println(m.group(1)); }
There is an alternative, but it can only be used with smaller, simpler patterns. A limited lookbehind width :
Java accepts quantifiers in lookbehind if the length of matching strings is within a given range. For example, (?<=cats?) valid because it can only match strings of three or four characters. Similarly (?<=A{1,10}) .
So this will also work:
m = Pattern.compile("(?<=value\\s{0,10}=\\s{0,10})\\d+").matcher(s); if(m.find()) { System.out.println(m.group()); }
See the Java demo .