Pergunta

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.

Foi útil?

Solução

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

should work

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top