Find Last Index Of by Regex in Java

后端 未结 7 1148
梦如初夏
梦如初夏 2021-01-17 17:32

i have a string %/O^/O%/O. I want to find the last / to split the string. First attemp was: \\/[POL]$ but that gets it inclusive the \"O\"

7条回答
  •  Happy的楠姐
    2021-01-17 18:23

            String name ="rami is good boy, and he is working for andorid,is completed";
        int lastSlash = name.lastIndexOf("is");
        String start = name.substring(0, lastSlash);
        String end = name.substring(lastSlash + 1, name.length());
        StringBuffer sb = new StringBuffer(name);
        sb.replace(start.length(), name.lastIndexOf(end)+1, "");
    
        System.out.println(sb.toString());
    

提交回复
热议问题