简体   繁体   English

正则表达式从链接中提取价值

[英]Regex to extract value from link

I have a String like file:///android_asset/GwyXUyisyq . 我有一个像file:///android_asset/GwyXUyisyq这样的字符串。 I want to extract the GwyXUyisyq from the rest of the string. 我想从字符串的其余部分提取GwyXUyisyq The value will change in every instance, but the file:///android_asset/ will always remain fixed. 该值将在每个实例中更改,但file:///android_asset/将始终保持固定。 What regex can I use to achieve the same? 我可以使用什么正则表达式来达到相同的目的?

You don't need a regex here : Just find the last index of / and replace everything before it :) 您在这里不需要正则表达式:只需找到/的最后一个索引,然后替换之前的所有内容即可:)

    String s = "file:///android_asset/GwyXUyisyq";
    System.out.println(s.replace(s.substring(0,s.lastIndexOf("/")+1), ""));

O/P :GwyXUyisyq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM