"Rupees,SIN_10_2,SIN_1000".replaceAll("SIN(\\w*?)","FSIN$1");
output : Rupees,FSIN_10_2,FSIN_1000
我也希望FSIN面对卢比,而且这个卢比可以是文本的开头还是结束。
所以这样出来
Expected output : FSIN_Rupees,FSIN_10_2,FSIN_1000
答案 0 :(得分:1)
您可以搜索此正则表达式:
(Rupees)|SIN_
并替换为:
FSIN_$1
此正则表达式使用替换匹配Rupees
或SIN_
。它在捕获的组中对Rupees
进行分组。替换为FSIN_$1
以获得所需的输出。
在Java中:
String repl = input.replaceAll("(Rupees)|SIN_", "FSIN_$1");
//=> FSIN_Rupees,FSIN_10_2,FSIN_1000