匹配字符串内的双单引号

匹配字符串内的双单引号

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

问题描述

我想要一个正则表达式,例如 'panic can''''t发生' 因为 panic can''''t发生.双单引号只允许相邻,'panic can't'发生' 应该分成两个字符串,panic can发生.

I want a regex that will match for example 'panic can''t happen' as panic can''t happen. Double single quotes are just allowed if they're next to each other, 'panic can't' happen' sgould be divided into two strings, panic can and happen.

到目前为止我得到了 \'[^\']*[\'\']?[^\']\' 但它不会按预期工作.

I got \'[^\']*[\'\']?[^\']\' so far but it won't work as expected.

谢谢!

推荐答案

您可以尝试以下操作:

'(?:[^']+|'')+'

  • ':匹配文字 '.
  • [^']+:匹配一个或多个不是'的字符.
  • '':匹配双 ''.
  • (?:[^']+|'')+:匹配前面两种模式的一次或多次出现.
  • ' 匹配结束的 '.
    • ': Matches a literal '.
    • [^']+: Matches one or more characters which are not '.
    • '': Matches double ''.
    • (?:[^']+|'')+: Matches one or more occurrences of the preceding two patterns.
    • ' matches the closing '.
    • Regex101 演示

      这篇关于正则表达式:匹配字符串内的双单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 20:29