I had this objective :
Given string : "Part1-part2-part3-part4-part5"
Split it on second occurrence of '-',
So I expect an array [ "Part1-part2", "part3-part4-part5" ]
What I did :
"Part1-part2-part3-part4-part5".split("(?<=^\\w+-\\w+)-"
But result on jdk 8 :
It does not find match of 2nd '-', and returns the entire string.
Evidence : https://ideone.com/myWppm
But when I tried on online regex processing websites and node.js (or chrome) [Believe me modern js supports lookbehind] the result is as expected.
Evidence : https://ideone.com/ttQWNr
Hack that I'm using right now (does not qualify to be a solution) :
Using lookahead instead of lookbehind, 3rd occurrence of '-' from the end
"Part1-part2-part3-part4-part5".split("-(?=\\w+-\\w+-\\w+$)");