Answer the question
In order to leave comments, you need to log in
How to put each match from a regular expression into an array?
We parse the page and get matches, we know in advance that there will be 452 matches. it should look like this mass[0] = "first match", mass[1] = "second match". It turned out only to put all one cell [0] = "all matches" =(
Teach me please!
String output = "";
StringBuffer totalOutput = new StringBuffer();
while ((output = br.readLine()) != null) {
Matcher regUrl = Pattern.compile("yes.>([0-9]{9})").matcher(output);
while (regUrl.find()) {
System.out.print(regUrl.group(1) + " ");
}
Matcher regUrl1 = Pattern.compile("blank.>([0-9]+)").matcher(output);
while (regUrl1.find()) {
System.out.println(regUrl1.group(1));
}
}
Answer the question
In order to leave comments, you need to log in
String line = "This order was placed for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find( )) {
System.out.println("Found value: " + m.group(0) );
System.out.println("Found value: " + m.group(1) );
System.out.println("Found value: " + m.group(2) );
} else {
System.out.println("NO MATCH");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question