Splitting a String in Java with underscore as delimiter

后端 未结 7 1078
野的像风
野的像风 2021-01-13 00:49

I have the following String (This format for the string is generic)

abc_2012-10-18-05-37-23_prasad_hv_Complete

I want to extract only

7条回答
  •  旧巷少年郎
    2021-01-13 01:09

    You can use a regex to extract the data:

    String input = "abc_2012-10-18-05-37-23_prasad_hv_Complete";
    String output = input.replaceAll("(?i)^[a-z]+_[^_]+_(\\w+)_[a-z]+$", "$1");
    

提交回复
热议问题