Reputation: 65
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!
Upvotes: 0
Views: 28
Reputation: 521103
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
Upvotes: 1