I have a StringBuilder object that I use to build one large string, separating the strings in the StringBuilder object using a "\n" character, how can I efficiently build a regex around that object without splitting the string and doing a loop?
For example say I have the below regex:
private static final regexPattern = "(([a-z[1-9]]+)||([1-9[a-z]]+))"
If I have this:
String[] myStringList = aStringList.split("\n");
I’m trying to build an effective regex using the regexPattern and each string in myStringList.
Pattern p = Pattern.compile(regexPattern + myStringList[i]);
Is there anyway to do this without splitting my stringBuilder into a loop and checking each and every string? Can I somehow build a large pattern around the entire StringBuilder object?
This will build a big “OR” regex out of your input, pre-pending
regexPatternto each part of the input string:Here’s some code that shows what you get:
Output: