且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java中查找Regex的最新索引

更新时间:2023-02-26 10:50:36

你需要使用正则表达式吗?将String。 lastIndexOf(/)用于查找索引,然后使用 String.substring(int start,int end),结果如何?或者您的实际数据是否不同且更复杂,需要正则表达式?用你提供的来分割最后一个/的字符串,这里是代码:

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);