input line is below
Item(s): [item1.test],[item2.qa],[item3.production]
Can you help me write a Java regular expression to extract
item1.test,item2.qa,item3.production
from above input line?
input line is below
Item(s): [item1.test],[item2.qa],[item3.production]
Can you help me write a Java regular expression to extract
item1.test,item2.qa,item3.production
from above input line?
I would split after trimming preceding or trailing junk:
String s = "Item(s): [item1.test], [item2.qa],[item3.production] ";
String[] ss = s.replaceAll("(^.*?\\[|\\]\\s*$)","").split("\\]\\s*,\\s*\\[");
// ss = {"item1.test", "item2.qa", "item3.production"};
A bit more concise:
String in = "Item(s): [item1.test],[item2.qa],[item3.production]";
Pattern p = Pattern.compile("\\[(.*?)\\]");
Matcher m = p.matcher(in);
while(m.find()) {
System.out.println(m.group(1));
}