本文介绍了正则表达式,查找由单引号括起来的单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个旧系统,当字符串包含单引号时,该系统会出现保存问题.

I am maintaining an old system that have saving issue when a string contains a single quote.

例如这些将失败:

"update table set column2 = 'O'Connell', column3 = 'O'Riordon' where column1 = 1"
"insert into table (column1, column2, column3, column4, column5, column6, column7) values('O'Reilley','state, postcode','',1,2,'O'Riordon')".

到目前为止,我已经想出了这个有效的 vbscript 正则表达式

So far I've came up with this working vbscript regular expression

([,=(]\s*'[^']*)'([^']*'\s*[,)\s])

是否可以在不使用头[(|=|\s|,]和尾[,|)|\s]的情况下编写vbscript正则表达式?

Is it possible to write a vbscript regular expression without using the header [(|=|\s|,] and trailer [,|)|\s]?

谢谢.

修复已发布的正则表达式以删除 |从标题和预告片.正则表达式使用如下

Fix the posted regex to remove | from header and trailer.The regexp is used as follows

regexp.replace("string","$1''$2")

推荐答案

我能想到的唯一方法只有在包含单引号的字符串从不包含空格时才有效.在这种情况下,您可以搜索

The only way I can think of works only if the string that contains the single quote never contains whitespace. In that case, you can search for

\B'([^'\s]*'[^'\s]*)'\B

说明:

\B        # Assert that there is no alphanumeric character before...
'         # the opening quote
(         # Match and capture...
 [^'\s]*  # Any number of non-quote/non-whitespace characters
 '        # One quote
 [^'\s]*  # Any number of non-quote/non-whitespace characters
)         # End of capture group 1
'         # Match the closing quote
\B        # Assert that there is no alphanumeric character afterwards

这篇关于正则表达式,查找由单引号括起来的单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 01:59