【发布时间】:2018-10-31 18:10:36
【问题描述】:
字符串看起来像
最大使用次数
A Borrower (or the Parent) may not deliver a Utilisation Request if as a result of the proposed Utilisation:<br/>
[10] or more Term Loans [(other than Incremental Company Loans)] would be outstanding; [or]<br/>
[15] or more Revolving Company Utilisations would be outstanding[; or<br/>
[20] or more Incremental Company Loans would be outstanding].<br/>
A Borrower (or the Parent) may not request that a Company A Loan [or an Incremental Company Loan] be divided if, as a result of the proposed division, [ 25 ] or more Company A Loans [or [ 50 ] or more Incremental Company Loans] would be outstanding.<br/>
[A Borrower (or the Parent) may not request that a Company B Loan or a Company C Loan be divided.]
预期输出:
[ 10 ] or more Term Loans [(other than Incremental Company Loans)] would be outstanding;
[ 15 ] or more Revolving Company Utilisations would be outstanding[; or
[ 20 ] or more Incremental Company Loans would be outstanding].
我尝试的方法似乎不起作用
Regex = '.*other than Incremental Company Loans.*'
这将返回整个段落。可能还有其他方法可以做到这一点,但我们只能使用 REGEX 来做到这一点。
【问题讨论】:
-
你的“行”是用
<br/>分隔的吗?那是HTML吗?最简单的方法是将所有<br/>替换为\n,并使用我已经与您分享的非正则表达式解决方案。 -
正确...这就是我们从数据库中取回字符串的方式...
-
那么,为什么是正则表达式?
inputText.Split(new[] {"<br/>"}, StringSplitOptions.None).Where(x => x.Contains("other than Incremental Facility Loans")). -
@WiktorStribiżew - 谢谢,但是使用 REGEX 是否可行?
-
是的,但是为什么呢?你能解释一下你在哪里使用它吗?正则表达式的性能/可读性将比纯代码差。
标签: regex