可能是因为你的段落不完整,所以不完全明白你的意思,如果是获取索引号,例如上述段落中的'[42]',请试试:
String pattern = "\\[(\\d+)\\]";
Pattern p = Pattern.compile(pattern );
Matcher m = p.matcher("你的段落");
while(m.find()){
System.out.println( m.group(1) );//打印每个索引
}
正则:[^\\.]*\\[.*\\][^\\.]*\\.
不要少句号。
实例代码如下:
public static void main(String[] args) {
String s = " areas [42]. experimentation.";
String regex = "[^\\.]*\\[.*\\][^\\.]*\\.";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group());
}
}