正则表达式替换AND

时间:2014-10-24 16:39:01

标签: regex

我正在尝试使用正则表达式来替换“AND”是这个子句但是我只想替换掉在'BLAH'之间的第一个“AND”。

有人可以帮我解决这个问题:

示例字符串

AND UserId= 3 AND CreditScore BETWEEN 680 AND 720 AND UserId = 3 AND CreditScore between 800 and 900 and UserId= 3 and 1 = 1 and Income between 212319 and 212320 and 1= 1

示例结果

AND UserId= 3 AND CreditScore BETWEEN 680 BlAH 720 AND UserId = 3 AND CreditScore between 800 BlAH 900 and UserId= 3 and 1 = 1 and Income between 212319 BlAH 212320 and 1= 1

1 个答案:

答案 0 :(得分:0)

启用不区分大小写的模式以执行不区分大小写的匹配。

(?i)(between\s+\d+\s+)AND(?=\s+\d+)

将匹配的字符串替换为$1BLAH

DEMO