Last active
February 22, 2019 01:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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