英文:
Looking for a regex to find a mailto link within a specific string of text
问题
我正在尝试构建一个正则表达式来查找特定HTML块中的mailto链接。
我有一个用于在页面上查找所有mailto链接的正则表达式:
$r = '`\<a([^>]+)href\=\"mailto\:([^">]+)\"([^>]*)\>(.*?)\<\/a\>`ism';
preg_match_all($r,$input, $matches, PREG_SET_ORDER);
然而,我想要找到包含在HTML块中的mailto链接:
<p style="text-align: center;"><strong>如果您希望选择退出/取消订阅未来的任何通信,请联系我们。选择退出</strong><br />
<strong>有关此隐私政策的请求和/或问题可以直接发送至:<a
href="mailto:domain@email.com" target="_blank" rel="noopener noreferrer"><span
style="color: #ff0000;">给我们发邮件</span></a>。</strong></p>
我正在尝试在多个站点上查找这个,而HTML块中唯一不变的部分是:
有关此隐私政策的请求和/或问题可以直接发送至<a href="mailto:domain@email.com"
因此,我正在尝试构建一个正则表达式,以在HTML块中找到此特定字符串并从中提取mailto链接。
英文:
I'm trying to build a regular expression to find a mailto link within a specific HTML block.
I have a regular expression to find all mailto links on a page:
$r = '`\<a([^>]+)href\=\"mailto\:([^">]+)\"([^>]*)\>(.*?)\<\/a\>`ism';
preg_match_all($r,$input, $matches, PREG_SET_ORDER);
However, I want to find the mailto link that is wrapped in an HTML block:
<p style="text-align: center;"><strong>Please contact us if you wish to opt-
out/unsubscribe from receiving any future communication. Opt-out</strong><br />
<strong> requests and/or questions regarding this privacy policy can be directed to: <a
href="mailto:domain@email.com" target="_blank" rel="noopener noreferrer"><span
style="color: #ff0000;">Email Us</span></a>.</strong></p>
I'm trying to find this on multiple sites, and the only part of the HTML block that doesn't change is this portion:
requests and/or questions regarding this privacy policy can be directed to <a href="mailto:domain@email.com"
So I'm trying to build a regular expression that will find this specific string within an HTML block and extract the mailto link from it.
答案1
得分: -2
以下内容应该可行。
提供静态文本的一部分,然后匹配"mailto"方案,然后捕获到闭合的双引号或单引号为止的每个值。
英文:
The following should work.
(?s)requests and/or.+?mailto:(.+?)[\"']
Just provide a portion of the static text, and then match up the "mailto" scheme, then capture every value up to the closing double, or single quotation mark.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论