需要我的Regex模式以任何提供的文本块中的任何顺序匹配多个术语

时间:2019-04-24 23:06:19

标签: regex

这有点特殊,但是我正在使用的应用程序仅实现了正则表达式参数的有限子集。最重要的是,它不支持除基本括号分组以外的任何组选项(即,没有命名的组,没有先行或后备的搜索,甚至没有(?:))。

我只希望获得TRUE / FALSE匹配项,不需要提取,替换或解析数据,我只需要知道指定的模式是否出现在主题字符串,是或否。

因此,我正在尝试使用基本的正则表达式构建一个模式,该模式将从文本块中找到4个提供的术语中的3个,并且可以按任意顺序触发匹配。

为方便起见,我尝试了以下操作:(\b(Term1|Term2|Term3|Term4)\b.*?){3,},但是它不起作用。奇怪的是,如果我将{3,}更改为{1,},它将找到每个术语的 all 个实例,表明该模式确实有效,但是当我告诉它时,我只想要一个匹配项是3个或更多实例,则找不到其中的任何。即使当我在Regex101上尝试该模式时也是如此,因此,这似乎不是我的应用程序内的引擎有限的故障。

在使用模式/b(TermX)/b时,主题文本中的所有单词都在其前后加上至少一个空格或句点,并且确实匹配。在一个样本数据中,将量词转换为{1,}时发现9个匹配项,但是当将其更改为{3,}时为零!

我对此模式缺少什么/误解?

编辑:返回到我要处理的有限功能集:我 only 能够指定模式。据我所知,没有提供用于指定条件(即不区分大小写,全局,多行,单行等)的机制,而且似乎没有默认设置这些条件。

修改:根据请求提供示例数据...

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<p><span style="text-decoration: underline;"><strong>EXPIRATION
NOTIFICATION&nbsp;FOR</strong></span><br>somedomain.com</p>
<p>Your domain service account is pending cancellation.</p>
<p></p>
<p>Notice#: xxx-xxx<br>Date: 04.24.2019<br>EXPIRATION DATE:
05.02.2019</p>
<p></p>
<p><b>Follow up on:<br></b><b><span style="text-decoration:
underline;"><span style="color: #ff6600;"><a href="https://spamurl.com"><span style="color: #ff6600; text-decoration: underline;">Secure Online
Payment</span></a></span></span><br></b><b>to complete.</b></p>
<p></p>
<p>Domain: somedomain.com<br>Registration Period: 1 Year/s<br>Amount:
$86.00 USD<br>Status: Pending (Unpaid)</p>
<p></p>
<p></p>
<p>Dear Name Lastname|CompanyName, ,<br>We are reaching out
to let you know that your notice #xxx-xxx&nbsp;is 5 days overdue.<br>We
are keeping your service for somedomain.com online, as your are still within
our grace period, and we want ensure the best possible service for
you.</p>
<p>Your account is in danger of being suspended if we do not receive your
payment soon. Please pay your notice here to avoid service
disruption.&nbsp;</p>
<p></p>
<p><b>Follow up on:<br></b><b><a href="https://spamurl.com"><span style="text-decoration: underline;"><span style="color: #ff6600;"><span style="color: #ff6600; text-decoration: underline;">Secure Online
Payment</span></span></span><br></a></b><b>to complete.</b></p>
<p></p>
<p><span style="font-size: xx-small; color: #c0c0c0;">Instructions and
Unlike Instructions from this Newsletter:</span><br><span style="font-size: xx-small; color: #c0c0c0;">This Email contains
information intended only for the individuals or entities to which it is
addressed. If you are not the intended recipient or the agent responsible
for delivering it to the intended recipient, or have received this Email in
error, please notify immediately the sender of this Email at the Help
Center and then completely delete it. Any other action taken in reliance
upon this Email is strictly prohibited, including but not limited to
unauthorized copying, printing, disclosure, or distribution. We do not
directly register or renew domain names. This is not a bill or an invoice.
This is a optimization offer for your website. You are under no obligation
to pay the amount stated unless you accept this purchase offer. Promotional
material is strictly along the guidelines oft he can-spam act of 2003. They
are in no way misleading. You have received this message because you
elected to receive notification offers. Thank you for your
cooperation.&nbsp;Unsubscribe Domain Service renew <span style="text-decoration: underline;"><a href="https://spamurl.com"><span style="color: #c0c0c0; text-decoration:
underline;">here</span></a></span>.</span></p>
<img src="https://spamurl.com" height="1" width="10"></body>
</html>

0 个答案:

没有答案