【问题标题】:If string includes and excludes?如果字符串包含和排除?
【发布时间】:2014-08-13 10:02:06
【问题描述】:

匹配要求:
如果字符串在" 之间且包含\n

例子(catch YES include "s):

NO NO NO    "NO NO NO"  "YES YES
YES"    NO  "NO"

这个正则表达式工作了一半:

\"((?!\").)*\"

这也不行:

\"((?!\").)*(?!.*\n)\"

尝试了很多案例,但没有找到解决方案。

【问题讨论】:

    标签: regex string language-agnostic regex-negation regex-lookarounds


    【解决方案1】:

    使用这个正则表达式:

    /"[^"]*\R[^"]*"/
    

    这是regex demo

    测试用例:

    NO NO NO    "NO NO NO"  "YES YES
    YES"    NO  "NO"
    

    匹配:

    "YES YES
    YES"
    

    【讨论】:

      猜你喜欢
      • 2018-04-02
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多