On Mar 13, 2018, at 11:42 AM, Remi Forax <fo...@univ-mlv.fr> wrote: > > it already exists :) > Stream<String> stream = Pattern.compile("\n|\r\n|\r").splitAsStream(string);
You want ` instead of " there! Somebody added support recently for `\R`, which is a more unicode-flavored version of your pattern (or just `\n`). Last time I looked it was missing; kudos to whoever added it in. There should be a fluent streamy syntax for splitting a string, string.splits(pat). Java's incomplete embrace of fluent syntax is old news, *but* there is something new here: String expression size. The raw strings are much larger than classic strings, and so they seem to need some notational assistance that doesn't always require them to be enclosed in round parens and mixed with other arguments. Having more fluent methods on String seems like a good move here. This goes beyond raw strings, and parsing is hard, but maybe there's room for richer versions of String.lines or String.splits, which can deliver both the surrounding whitespace and one or more fields, for each line (or each paragraph or whatever): public Stream<MatchResult> matchResults(String regex) { return Pattern.compile(regex).matcher(this).results(); } The point is that a MatchResult delivers both the whole substring and any groups embedded in it as part of the match. Plus indexes, which is nice sometimes. — John