0

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!

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.