Home > Enterprise >  How to find a string at a specific location with regex with java?
How to find a string at a specific location with regex with java?

Time:06-08

How to find a string at a specific location with regex?

choryangStn_110_220114_one_0.sbm choryangStn_110_220114_two_0.sbm choryangStn_110_220114_three_0.sbm I want to get one, two, three from

I wonder how this is possible.

best regards!

CodePudding user response:

We can use String#replaceAll here:

String filename = "choryangStn_110_220114_one_0.sbm";
String num = filename.replaceAll(".*_(\\w )_\\d \\.\\w ", "$1");
System.out.println(num);  // one
  • Related