50,545
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.*;
public class Test {
public static void main(String[] args) {
String str = "asdsd[one]sakds[two]sdsd";
Pattern pattern = Pattern.compile("\\[.*?\\]");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
输出
[one]
[two]