java清除字符串之间的字符串
例如,我有这样一个字符串:
String myString = "Hello my name is Skypit"
如何清除“我的”和“是”之间的所有内容? “我的”和“是”永远不会改变,但两者之间的一切都会改变。 所以这个例子的结果应该是“Hello myis Skypit”
你可以在下面搜索框中键入要查询的问题!
例如,我有这样一个字符串:
String myString = "Hello my name is Skypit"
如何清除“我的”和“是”之间的所有内容? “我的”和“是”永远不会改变,但两者之间的一切都会改变。 所以这个例子的结果应该是“Hello myis Skypit”
# 1 楼答案
您可以将
(.*my).*(is.*)
与replaceAll
一起使用(.*my)
:捕获所有内容,直到my
,其中(.*my)
由$1
表示(is.*)
:捕获从is
到结尾的所有内容,其中(is.*)
由$2
表示输出:
获取
my
和is
之间的内容演示