0

I have this: start_xxx_end_Leftstart_xxx_end_Right

How can I use the regular expression to remove characters between start and end (inclusive) so that I can get the following string:

_Left_Right

I tried this regex in java but it removes EVERYTHING between start and end:

start(.*)end

1 Answer 1

3

Just use replaceAll method to replace the substring from start to end: -

String str = "start_xxx_end_Leftstart_xxx_end_Right";
str = str.replaceAll("start.*?end", "");
System.out.println(str);

OUTPUT : -

"_Left_Right"
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.