关于多项选择题的Regex w/JavaScript

关于多项选择题的Regex w/JavaScript,javascript,regex,Javascript,Regex,我正在尝试解析Anki抽认卡的.docx多项选择题 我想从docx集合一组匹配的“问题”和“答案” 在尝试回答问题时,我无法让正则表达式以我想要的方式匹配每一个问题 示例问题: 1. Hormones and other signal molecules bind with ____ affinities to their receptors and are produced at concentrations ____ their KD values. a. low; far abo

我正在尝试解析Anki抽认卡的.docx多项选择题

我想从docx集合一组匹配的“问题”和“答案”

在尝试回答问题时,我无法让正则表达式以我想要的方式匹配每一个问题

示例问题:

    1.  Hormones and other signal molecules bind with ____ affinities to their receptors and are produced at concentrations ____ their KD values.
a.
low; far above
b.
moderate; far above
c.
moderate; equivalent to
d.
high; far below
e.
very high; equivalent to


ANS:    E    

    2.  Steroid hormones, such as glucocorticoids, effect their action by:
a.
binding to a plasma membrane receptor, which stimulates a signal transduction pathway within the cell
b.
binding to a plasma membrane receptor, which stimulates the receptor to enter the cell
c.
entering into the cell and affecting the production of secondary messengers
d.
entering into the cell and then acting as transcription regulators
e.
both a and d are correct


ANS:    E    

    3.  All are unifying features of polypeptide hormones EXCEPT that they are:
a.
originally synthesized with signal sequences.
b.
synthesized as inactive preprohormones.
c.
activated from preprohormones to hormones by phosphorylation.
d.
may produce several different peptide hormones with suitable processing.
e.
all are true.


ANS:    C    

    4.  Each of the following statements is true EXCEPT:
a.
epinephrine is an amino acid derivative
b.
steroid hormones can enter cells and regulate transcription
c.
insulin is a polypeptide hormone
d.
progesterone is a polypeptide hormone
e.
all of the above are true


ANS:    D    

    5.  The acrosome reaction, involving ion channel induced release of acrosomal enzymes used by sperm to attack the egg, is induced by:
a.
estrogen.
b.
testosterone.
c.
dihydrotestosterone (DHT).
d.
progesterone.
e.
cortisol.


ANS:    D    
我使用的是
/(\d.)[^\d][^ANS$]+/gm
,但在解析整个文档时,它会不断跳过第二个和第三个问题,以及更多问题

任何建议都将不胜感激。

(\d.)[^\d][^ANS$]+
模式匹配一个数字(
\d
),后跟任何字符(
),然后后跟除数字以外的任何字符(
[^\d]
),然后后跟除
a
N
S
$
之外的任何一个或多个字符(
[^…]
是一个否定字符类,其中
$
失去了其特殊意义,它匹配类中的单个字符,而不是序列)

要修复正则表达式,可以使用

/^\s*(\d+\..*(?:\r?\n(?!\s*ANS:).*)*)\r?\n\s*(ANS:.*)/gm

详细信息

  • ^
    -行的开头(因为
    m
    修饰符使
    ^
    匹配行的开头而不是整个字符串)
  • \s*
    -0个或更多空格
  • -第1组开始:
    • \d+
      -1个或多个数字
    • \。
      -一个点
    • *
      -行的其余部分
    • (?:\r?\n(?!\s*ANS:).*)
      -0或更多连续出现的
      • \r?\n
        -CRLF或LF换行符
      • (?!\s*ANS:)
        -后面不跟0+空格(
        \s*
        ),后面跟
        ANS:
        子字符串(
        (?!…)
        是一个负前瞻,如果 其模式立即位于当前位置的右侧)
      • *
        -行的其余部分
  • -第1组结束
  • \r?\n
    -换行符
  • \s*
    -0+空格
  • (ANS:.*)
    -第2组捕获
    ANS:
    和行的其余部分
JS演示:

var rx=/^\s*(\d+\..*(?:\r?\n(?!\s*ANS:)*))\r?\n\s*(ANS:*)/gm;
变量s="1.激素和其他信号分子与其受体具有亲和力,并以其KD值的浓度产生。\r\na。\r\nlow;远高于\r\nb。\r\n适度;远高于\r\nc。\r\n适度;相当于\r\nd。\r\nhigh;远低于\r\ne。\r\n极高;相当于\r\n\r\n\r\n\r\nANS:E\r\n\r\n\r\n 2.类固醇激素,如作为糖皮质激素,其作用是:\r\na。\r\n与质膜受体结合,刺激细胞内的信号转导途径。\r\n与质膜受体结合,刺激受体进入细胞。\r\n进入细胞并影响次级信使的产生。\r\n进入细胞,然后充当转录调节器。\r\n a和d都是正确的\r\n\r\n\r\n:E\r\n\r\n 3.所有这些都是多肽激素的统一特征,除了它们是:\r\na。\r\n最初是通过信号序列合成的。\r\nb。\r\n作为非活性前激素合成的。\r\nc。\r\n从前激素合成的nes通过磷酸化作用生成激素。\r\nd。\r\n通过适当的处理,可以生成几种不同的肽类激素。\r\ne。\r\n所有都是正确的。\r\n\r\n\r\n南斯:C\r\n\r\n 4.以下每种说法都是正确的,除了:\r\na。\r\nepinephrine是一种氨基酸衍生物\r\nb。\r\n类激素可以进入细胞并调节转录\r\n\nc。\r\n胰岛素是一种多肽激素\r\n和。\r\n孕酮是一种多肽激素\r\n。\r\n以上所有内容都是正确的\r\n\r\n答案:D\r\n\r\n 5.顶体反应,涉及精子攻击卵子所用的顶体酶的离子通道诱导释放,是由:\r\na。\r\nestrogen。\r\nb。\r\n顶体激素。\r\n罗茨甾酮(DHT)。\r\nd。\r\n罗茨甾酮。\r\ne。\r\n罗茨甾酮。\r\n\r\n\r\n南:D”
var-m;
var qst=[],ans=[];
while(m=rx.exec){
push(m[1].trim());
ans.push(m[2].trim());
}
document.body.innerHTML+=“”+JSON.stringify(qst,0,4)+“”;
/\d.+/gm
/\d\D+(?=ANS)/gm
document.body.innerHTML++=“JSON.stringify(ans,0,4)+;”
模式匹配一个数字(
\d
),后跟任何字符(
),然后后跟除数字以外的任何字符(
[^\d]
),然后后跟除
A
N
S
$
以外的任何1个或多个字符(
[^…]
是一个否定字符类,其中
$
失去其特殊含义,并且它与类中的单个字符相匹配,而不是序列)

/\d.+/gm
/\d\D+(?=ANS)/gm
要修复正则表达式,可以使用

/^\s*(\d+\..*(?:\r?\n(?!\s*ANS:).*)*)\r?\n\s*(ANS:.*)/gm

详细信息

  • ^
    -行的开头(因为
    m
    修饰符使
    ^
    匹配行的开头而不是整个字符串)
  • \s*
    -0个或更多空格
  • -第1组开始:
    • \d+
      -1个或多个数字
    • \。
      -一个点
    • *
      -行的其余部分
    • (?:\r?\n(?!\s*ANS:).*)
      -0或更多连续出现的
      • \r?\n
        -CRLF或LF换行符
      • (?!\s*ANS:)
        -后面不跟0+空格(
        \s*
        ),后面跟
        ANS:
        子字符串(
        (?!…)
        是一个负前瞻,如果 其模式立即位于当前位置的右侧)
      • *
        -行的其余部分
  • -第1组结束
  • \r?\n
    -换行符
  • \s*
    -0+空格
  • (ANS:.*)
    -第2组捕获
    ANS:
    和行的其余部分
JS演示:<