单引号内单引号的正则表达式 [英] Regex for single quote within single quotes
本文介绍了单引号内单引号的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这就是我想要做的:
OK, so this is what I'm trying to do :
- 我有一个完整的 SQL 脚本
- 值中的某些
的
未正确转义 - 例如如果我们有
'children's shoes'
,我想用'children\'s shoes'
替换它
- I've got a complete SQL script
- Some of the
's
inside the values have not been properly escaped - e.g. if we have
'children's shoes'
, I want to replace it with'children\'s shoes'
那么,有什么建议吗?(我尝试了各种解决方法,但似乎无法正确解决...)
So, any suggestions? (I've tried various workarounds but I don't seem to be able to get it right...)
更新:
'.+?'
肯定匹配值 - 但我如何匹配值中的的
?
'.+?'
sure matches the values - but how do I match the's
s within the values?
这是我尝试匹配的 RegExr 示例:http://regexr.com?368bo
Here's a RegExr example of what I'm trying to match : http://regexr.com?368bo
更新二:
好的,我想我会选择[a-z]'s
.似乎它正在捕捉我需要的东西.并替换为 $1\'s
.
OK, I think I'll go with [a-z]'s
. It seems like it's capturing what I need. And replace with $1\'s
.
推荐答案
匹配这个正则表达式:
('[^']*)'s([^']*')
并替换为:
$1\'s$2
这篇关于单引号内单引号的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文