“It’s hard not to pine for a better world, but this is a game that makes it happen. That may be the biggest metaphor of all.”
Game Trailer:
TrailerQ:
Cannot figure out why my regex is “not returning” a match
I have the following Java code:
String str = “m1 = 1, 2, 3, 4, 5, 6
” +
“m2 = 1, 2, 3, 4, 5, 6
” +
“m3 = 1, 2, 3, 4, 5, 6
” +
“m4 = 1, 2, 3, 4, 5, 6
” +
“m5 = 1, 2, 3, 4, 5, 6
” +
“m6 = 1, 2, 3, 4, 5, 6”;
System.out.println(Pattern.compile(“((\\w+) = (\\d+,\\d+),.*))”).matcher(str).matches());
I want to extract out m1, m2, m3, m4, m5, and m6 into different arrays. So my expected results are:
m1 = 1, 2, 3, 4, 5, 6
m2 = 1, 2, 3, 4, 5, 6
m3 = 1, 2, 3, 4, 5, 6
m4 = 1, 2, 3, 4, 5, 6
m5 = 1, 2, 3, 4, 5, 6
m6 = 1, 2, 3, 4, 5, 6
I got this code from an answer here: Use regex to get multiple lines
But my regex is not returning matches for “m1 = 1, 2, 3, 4, 5, 6” and “m2 = 1, 2, 3, 4, 5, 6” (the missing matches from my expected results). Why is that?
What am I doing wrong?
A:
Modified code – note the minor changes:
String str = “