Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SingingBush/fccd964259f282d85de3c0e8d74f84a8 to your computer and use it in GitHub Desktop.
Save SingingBush/fccd964259f282d85de3c0e8d74f84a8 to your computer and use it in GitHub Desktop.
Create a Java 8 Stream of Strings matching a regex on a given String
private Stream<String> regexPatternMatchStream(final String pattern, final String target) {
final Matcher matcher = Pattern.compile(pattern).matcher(target);
final Stream.Builder<String> sb = Stream.builder();
while (matcher.find()) {
sb.add(matcher.group());
}
return sb.build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment