Find Last Index Of by Regex in Java

后端 未结 7 1098
梦如初夏
梦如初夏 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条回答
  •  粉色の甜心
    2021-01-17 18:17

    Do you need to use regular expressions for this? Would String.lastIndexOf("/") work to find the index, and then use String.substring(int start, int end) with the result? Or is your actual data different and more complicated, requiring regular expressions? With what you provided to split the string on the last /, here's code:

    int lastSlash = mystring.lastIndexOf("/");
    String start = mystring.substring(0, lastSlash);
    String end = mystring.substring(lastSlash + 1, mystring.length);
    

提交回复
热议问题