I've got a code which involves using Matcher and Pattern classes, however I've got a text which contains multiple instances of the same "pattern". My code however returns every found match and puts it in a single string. I want to put every match found in a different string/array. Can you give me an example code?
Your question is not clear to me.
But, I assume, Your emphasized textinput strings are in array or list. And you want to create new array or list from the input strings which matches the regex.
Then here is the solution for this:
Pattern p = Pattern.compile("Java");//any regex
List<String> inputStrings = new ArrayList<String>();
List<String> matched = new ArrayList<String>();
//test strings
inputStrings.add("Java hello");
inputStrings.add("Javaaa");
inputStrings.add("aaaJavaaa");
inputStrings.add("Jvaaa");
//do
for (String curStr : inputStrings) {
Matcher matcher = p.matcher(curStr);
while (matcher.find()) {
matched.add(curStr);
}
}