I'm reading in a list of strings from a List<String>. The strings look like this:
blah1
blah2
blah3
blah4
In java, I'd like to build a regex that checks for a pattern like this (myString/|yourString) and concatenate that to each of the strings in the list above while doing a pattern match against the lines of a file.
So I do this (the code below is just snippits):
String pattern = "(myString/|yourString.)"
private String listAsString;
private void createListAsStrings() {
StringBuilder sb = new StringBuilder();
for(String string : stringList) {
sb.append(string + "|"); # using the pipe hoping it will do an OR in the regex
}
listAsString = sb.toString();
}
To build the pattern, I'm trying to do the following:
Pattern p = Pattern.compile(pattern + listAsString);
But when I get to running the matcher it doesn't go through each string in the list of strings from my stringbuilder. And then the last problem is that my last string will contain a |.
Is there a way to match myString/blah1 or yourString.blah1 or myString/blah2 etc.. using a regex against each line in a file?
There is a lot of code, so I just posted what seemed relevant.