user18045244
user18045244

Reputation: 65

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

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

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

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

Related Questions