1.java中替换字符制定字符(替换正则字符串)
将下划线("_")替换为斜线和下划线"\_" 只能使用replace,使用replaceAll失败
platform_Name = platform_Name.replace("_", "\\_");
如aaaa_bb_cdda_ds_d_s_a替换后为aaaa\_bb\_cdda\_ds\_d\_s\_a
2.sql中使用escape符号
如:
mysql中的test表中数据以下
+----+-----------+
| id | name |
+----+-----------+
| 1 | vc_177 |
| 2 | vc_177New |
| 3 | v__177New |
| 4 | v__1_New |
| 5 | vcvms |
+----+-----------+
选择须要匹配v__ 指望获得数据为
v__177New
v__1_New
则须要使用一下语句:
select * from test t where t.name like '%v\_%' escape
'\\';
便可
此时_下划线再也不是匹配符
3.oracle中的语法则是:(escape后面的斜线数量不一致)
select * from test t where t.name like '%v\_%' escape '
\';