I have a string

String origStr = "/unwanted/wanted1/wanted2/and_so_on"

i want to make this as

String finalStr = "wanted1/wanted2/and_so_on"

I thought of doing that using regEx in Java. But struck on this.

有帮助吗?

解决方案

origStr.replaceFirst("/[^/]+/", "");

should work

其他提示

You can do something like this -

    String str = "/unwanted/wanted1/wanted2/and_so_on";
    String temp = str.substring(str.indexOf("/", 1)+1);
    System.out.println(temp);

Without using regEx.You can use split("/") method to make it into String array.And cutting down the first element.

String [] arr= origSTr.split("/");

Use this arr as you wish.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top