Reza soumi :
I'm sure I used to know this, and I'm sure this is covered somewhere but since I couldn't find I want to use regex to elicit the information that is required.
For example, the text is
"!#man,money=23,save=10#!lweoi!#man,money=14,save=5#!hasg!#man,money=33,save=20#!"
So, I want to elicit all the 3 form and store it to arraylist but when I use the regex form
"!#man,money=\\d+,save=\\d+#!"
it save all of it to one part.
How can I do it? Thanks
User9123 :
Use group:
public class RegExpPsvm {
public static void main(String[] args) {
String inputStr = "!#man,money=23,save=10#!lweoi!#man,money=14,save=5#!hasg!#man,money=33,save=20#!";
Pattern pattern = Pattern.compile("!#man,money=(\\d+),save=(\\d+)#!");
Matcher matcher = pattern.matcher(inputStr);
while (matcher.find()) {
String fullText = matcher.group(0);
String manAndMoney = matcher.group(1);
String save = matcher.group(2);
System.out.println("fullText = " + fullText);
System.out.println("manAndMoney = " + manAndMoney);
System.out.println("save = " + save);
}
}
}