繁体   English   中英

Java 正则表达式替换'text with N'text'

[英]Java Regular expression to replace 'text with N'text'

最近我们意识到,针对 NVARCHAR 列执行的 SQL 语句在搜索字符串之前没有 append N。

SQL 语句是通过一些核心业务逻辑生成的,我们不拥有该 class。 所以现在我需要 append N在 where 子句中的搜索字符串之前。

N 用于指定 SQL 中的 unicode 字符串。

例子

输入字符串: Select * from table where key = 'text'

Output 字符串: Select * from table where key = N'text'

我正在 Java 中尝试一些正则表达式,我可以用 N'text' 替换'text'

这就是您可以使用正则表达式的方式:

int start = input.start("''\w+''"); // for any character use "''.+''" and for alphanumeric use "''[\w\d]+''"
input = input.substring(0, start) + "N" + input.substring(start);

有关正则表达式模式的更多信息,请使用: https://www.rexegg.com/regex-quickstart.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM