我有以下字符串:
In order to take this course, you must:<br>
<br>
√ Have access to a computer.<br>
<br>
√ Have continuous broadband Internet access.<br>
<br>
√ Have the ability/permission to install plug-ins (e.g. Adobe Reader or Flash) and software.<br>
<br>
√ Have the ability to download and save files and documents to a computer.<br>
<br>
√ Have the ability to open Microsoft file and documents (.doc, .ppt, .xls, etc.).<br>
<br>
√ Be competent in the English language.<br>
<br>
√ Have access to a relational database management system. A good open-source option is MySQL (<a href="http://dev.mysql.com" target="_blank">dev.mysql.com</a>).<br>
<br>
√ Have completed the Discrete Structures course.<br>
<br>
√ Have read the Student Handbook.
我试图选择中间的文字(不包括标题,编码空格和<br>
),例如,第一场比赛应为:Have access to a computer.
我已经尝试了以下两项,但无法使其发挥作用。
这一行选择整行:^(?:√([( )|\s]*))(.*)(?:(\<br\\?\>)*)$
,我尝试拨打Regex.Matches(requirements.InnerHtml, RequirementsExtractorRegex, RegexOptions.Multiline)[0].Captures[0].Value
,此处的值为:√ Have access to a computer.<br>
。
这个没有选择任何东西:^(?<=√([( )|\s]*))(.*)(?=(\<br\\?\>)*)$
我做错了什么?
答案 0 :(得分:1)
对正则表达式进行略微修改会产生(几乎,见下文)所需的结果
^(?:√(?: |\s)*)(.*)(?:<br/?>)
引用组#1中的目标匹配
Regex.Matches(requirements.InnerHtml, RequirementsExtractorRegex, RegexOptions.Multiline)[0].Groups[1].Value
使用多行匹配选项在regexstorm上进行了测试。
<强> 买者 强>
由于非可选的br元素,正则表达式匹配所有目标出现但最后一个出现。量化该部分包括匹配中的最后一次出现但使得捕获组#1包含终止该行的br元素 - 贪婪的通用匹配覆盖。添加行终止锚点会阻止匹配(虽然它不应该在我对规范的理解中 - 可能是测试环境的工件?)。