【问题标题】:Need help for regex需要正则表达式的帮助
【发布时间】:2015-10-06 22:38:13
【问题描述】:

我正在使用正则表达式来查找答案选择及其描述。 到目前为止,它运行良好,但问题是我无法弄清楚如何在不包含下一个选项的情况下包含多行描述。

我当前的正则表达式:

^(Choice [A-I] \(.*\) +(?:is incorrect. )?($|\r?.*))

测试用例:

Choice B (Predominance of eosinophils) zfdfdfbhdfdfdf
fgdfgdfgdfdfdfhd fgdfgdfgdsgsf
sgsgdfgdf gdfgdfgdfgdfgd gdfg
Choice C (Monosodium urate crystals) fghfdghfghfghfh
Choice D (Spirochetes) is incorrect fghfghfghfghfghf
Choice E (Predominance of polymorphonuclear cells) 

Demo on regex101

我需要选择 B 之后的两个随机文本句子也包含在选择 B 匹配中,但不包括选择 C。

【问题讨论】:

    标签: javascript regex text


    【解决方案1】:

    你可以试试:

    (Choice [A-I] \(.*\) )(((?!Choice)[^\n]+[\n]?)+)?
    

    Demo on regex101

    说明

    • (?!Choice): 字符串不以“Choice”开头

    • [^\n]: 任何字母,除了“\n”

    【讨论】:

    • 工作就像魅力!在其他类似的情况下也使用了这个原理。谢谢!
    猜你喜欢
    • 2012-11-30
    • 2023-03-19
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    相关资源
    最近更新 更多