I have a string with multiple "message" inside it. "message" starts with certain char sequence. I've tried:
String str = 'ab message1ab message2ab message3'
Pattern pattern = Pattern.compile('(?<record>ab\\p{ASCII}+(?!ab))');
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
handleMessage(matcher.group('record'))
}
but \p{ASCII}+ greedy eat everything.
Symbols a, b can be inside message only their sequence mean start of next message
"ab "or whatever char sequence you have in front of it.String[] res =str.split("(?!^)\\s*(?=ab)");. If theabis always at the end of the word, add\\bafterabin the pattern (=>"(?!^)\\s*(?=ab\\b)").\p{ASCII}+with[^ ab]+