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
sql where 正则替换
最新推荐文章于 2024-08-02 00:01:57 发布
该博客主要展示了如何在Java中使用正则表达式进行字符串匹配和替换操作。代码示例中,定义了一个静态字符串`where2`,通过`Pattern.compile(regex)`和`matcher.find()`方法检查字符串是否符合特定的正则模式。如果找到匹配项,使用`replaceFirst()`方法移除匹配的部分。这展示了Java中的基础字符串处理和正则表达式应用。
2168

被折叠的 条评论
为什么被折叠?



