天天看点

字符串匹配所有子串坐标

private List<Integer> getAllIndex(String content,String groupf) {
  List<Integer> res = new ArrayList<Integer>();
  //记录位置
  Integer index;
  //需要匹配的次数
  String[] split = content.split(groupf);
  if(split.length>2){
    index = content.indexOf(groupf);
    res.add(index);
    for (int i= 0;i<split.length-2 ;i++){
      index = content.indexOf(groupf,index+groupf.length());
      res.add(index);
    }
  }else{
    index = content.indexOf(groupf);
    res.add(index);
  }
  return res;
}