Reputation: 2244
I try to get from String like (111,222,ttt,qwerty)
list of values
I try this pattern:
String area = "(111,222,ttt,qwerty)";
String pattern = "\\([([^,]),*]+\\)";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(area);
System.out.println(m.groupCount());
ArrayList<String> values = new ArrayList<String>();
while(m.find()){
System.out.println("group="+m.group(1));
values.add(m.group());
}
But I found that group count is zero. What I`ve missed?
Upvotes: 1
Views: 125
Reputation: 533890
If you know there is only one set of brackets ()
String text = "aaa,bbb(111,222,ttt,qwerty),,,cc,,dd";
String[] parts = text.substring(text.indexOf('(')+1, text.indexOf(')')).split(",");
// parts = [ 111, 222, ttt, qwerty ]
Upvotes: 0
Reputation: 5101
If you only have words containing english letters and numbers without spaces,
You can use following regexp for achieving this.
String pattern = "[a-zA-Z0-9]+";
It checks for groups of characters which only contains digits and uppercase/lowercase English letters.
Upvotes: 0
Reputation: 62469
Assuming you always have the same format of the string, you could simply try:
String[] split = area.split("\\(|\\)|,");
Upvotes: 2