Skip to content

Instantly share code, notes, and snippets.

@ariesmcrae
Last active February 22, 2019 01:51
Show Gist options
  • Save ariesmcrae/5f327a143bcf672ce08cca57a33c2859 to your computer and use it in GitHub Desktop.
Save ariesmcrae/5f327a143bcf672ce08cca57a33c2859 to your computer and use it in GitHub Desktop.
Combine list and array into a comma separated value to produce a regex pattern
Stream<String> states = Stream.of("NSW", "VIC", "SA", "WA", "ACT", "QLD", "TAS", "NT");
Stream<String> additionalStates = {"AUCKLAND", "CHRISTCHURCH"};
List<String> combinedStates = Stream.concat(states, additionalStates).collect(Collectors.toList());
String regexPattern = "\\A(" + StringUtils.join(combinedStates, "|") + ")\\z";
// \A(NSW|VIC|SA|WA|ACT|QLD|TAS|NT|SPACE)\z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment