输入行在下面
Item(s): [item1.test],[item2.qa],[item3.production]
Run Code Online (Sandbox Code Playgroud)
你能帮我写一个Java正则表达式来提取吗?
item1.test,item2.qa,item3.production
Run Code Online (Sandbox Code Playgroud)
从上面的输入线?
Jar*_*red 82
更简洁一点:
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));
}
Run Code Online (Sandbox Code Playgroud)
你应该使用积极的前瞻和后视:
(?<=\[)([^\]]+)(?=\])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
56119 次 |
最近记录: |