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

4

1 回答 1

3

只需使用replaceAll方法将子字符串替换startend: -

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

输出 : -

"_Left_Right"
于 2012-11-15T20:09:18.077 回答