sql where 正则替换

该博客主要展示了如何在Java中使用正则表达式进行字符串匹配和替换操作。代码示例中,定义了一个静态字符串`where2`,通过`Pattern.compile(regex)`和`matcher.find()`方法检查字符串是否符合特定的正则模式。如果找到匹配项,使用`replaceFirst()`方法移除匹配的部分。这展示了Java中的基础字符串处理和正则表达式应用。
public class SQLTest {

    private static String where3 = "Where dsName = '1' and ds = 1 and a = 1";
    private static String where2 = "Where ds =1 And dsName = '1'";
    private static String where1 = "Where ds=1";
    private static String regex = "((and|or)\\s*ds\\s*=\\s*\\w*)|(ds\\s*=\\s*\\w*\\s*(and|or))";


    public static void main(String[] args) {
        //1.ds = 1
        where2 = where2.toLowerCase();
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(where2);
        if (matcher.find()) {
            where2 = where2.replaceFirst(regex, "");
            System.out.println(true);
        }
        System.out.println(where2);


    }

}
```java

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值