【发布时间】:2011-12-22 22:35:00
【问题描述】:
我有以下字符串,如何在 Java 中搜索和替换它?
之前
*animal is a *ANImal and *Bird is a *bIrd.
搜索替换后应该是 *animal = Dog and *bird = 孔雀
Dog is a Dog and Peacock is a Peacock.
我已经尝试替换这种模式的出现 - (?i)\\*animal 但它不起作用。我做错了什么?
【问题讨论】:
-
使用 Pattern.quote() 示例:str.replaceAll("(?i)"+Pattern.quote("*animal"), "Dog") 与 "*bird" 相同
标签: java regex string search replace