extract substring in java using regex

前端 未结 7 1656
走了就别回头了
走了就别回头了 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:06

    String s = Last one: http://abc.imp/Basic2#URPlus1_S2_3,"
    String result = s.replaceAll(".*#", "");
    

    The above returns the full String in case there's no "#". There are better ways using regex, but the best solution here is using no regex. There are classes URL and URI doing the job.

提交回复
热议问题