使用“.+?”实现中间模糊匹配的代码:
public class Test { public static void main(String[] args) { String str="总会在某一个回眸的时刻醉了流年,濡湿了柔软的心.总会有某一个回眸的时刻醉了流年,濡湿了柔软的心"; str=str.replaceAll("总会在.+?流年", "总会有某一个回眸的时刻醉了流年"); System.out.println(str); } }
注:只能模糊匹配中间不确定的字符串
使用“.+?”实现中间模糊匹配的代码:
public class Test { public static void main(String[] args) { String str="总会在某一个回眸的时刻醉了流年,濡湿了柔软的心.总会有某一个回眸的时刻醉了流年,濡湿了柔软的心"; str=str.replaceAll("总会在.+?流年", "总会有某一个回眸的时刻醉了流年"); System.out.println(str); } }
注:只能模糊匹配中间不确定的字符串
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。