extract substring in java using regex

前端 未结 7 1634
走了就别回头了
走了就别回头了 2020-12-10 22:25

I need to extract \"URPlus1_S2_3\" from the string:

\"Last one: http://abc.imp/Basic2#URPlus1_S2_3,\" 

using regular expressi

7条回答
  •  攒了一身酷
    2020-12-10 23:29

    If you just want everything after the #, use split:

    String s = "Last one: http://abc.imp/Basic2#URPlus1_S2_3," ;
    System.out.println(s.split("#")[1]);
    

    Alternatively, if you want to parse the URI and get the fragment component you can do:

    URI u = new URI("http://abc.imp/Basic2#URPlus1_S2_3,");
    System.out.println(u.getFragment());
    

提交回复
热议问题