正则表达式 - HTML 中的网络钓鱼尝试
RegEx - phishing attempts in HTML
我需要你的帮助:(
我想要什么:
匹配字符串,如果 url.text AND url.href 都包含 URL,它们不相等(没有协议和子域)。
它应该像这样工作:
<a href="http://www.test1.net/dir1/index.html" target="_blank">test1.net/admin</a> <-- NOT MATCH
<a href="https://test2.com">THIS SITE</a> <-- NOT MATCH
<a href="https://subdomain.test3.org">test2.org</a> <-- MATCH
<a href="http://www2.test4.com" target="_blank">https://global.test4.com/index.html</a> <-- NOT MATCH
<a href="http://eu.test5.com">https://evil.com/eu.test5.com/</a> <-- MATCH
<a href="http://eu.site6.com/index.html" target="_blank">https: // eu. evil. com</a> <-- MATCH
<a href="https://site7.com/">http://www.site7.com/123/test</a> <-- NOT MATCH
我开始写类似 this 的东西,但是我的代码在做相反的事情时遇到了问题。
帮我弄清楚如何制作我想要的东西。
您的原始表达式设计得很好,但我会使用一些语句,例如:
(?!.*.*)
或:
(?!((?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?()).*)
内,要绕过 url.text
中的相同域,可能使用类似于以下的一些表达式:
(?i)<a\s+href="(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?"[^>]*>(?!.*.*)(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?.*?<\/a>
或者更准确地说:
(?i)<a\s+href="(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?"[^>]*>(?!((?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?()).*)(?:https?:\s*\/\/\s*)?(?:\s*w{3}\.\s*)?(?:[^"\/]*\.\s*)?([a-z0-9_-]+\s*\.\s*[a-z0-9_-]{2,6}\s*)(\/[^"]*)?.*?<\/a>
您最有可能想要修改的内容,并更改边界。例如,您可以在任何您想要留出一些空格的地方添加 \s*
,或者使用双界量词 \s{0,5}
.
Demo
如果您希望 simplify/modify/explore 表达式,regex101.com. If you'd like, you can also watch in this link 的右上面板已经解释了它如何与一些样本输入相匹配。
我需要你的帮助:(
我想要什么:
匹配字符串,如果 url.text AND url.href 都包含 URL,它们不相等(没有协议和子域)。
它应该像这样工作:
<a href="http://www.test1.net/dir1/index.html" target="_blank">test1.net/admin</a> <-- NOT MATCH
<a href="https://test2.com">THIS SITE</a> <-- NOT MATCH
<a href="https://subdomain.test3.org">test2.org</a> <-- MATCH
<a href="http://www2.test4.com" target="_blank">https://global.test4.com/index.html</a> <-- NOT MATCH
<a href="http://eu.test5.com">https://evil.com/eu.test5.com/</a> <-- MATCH
<a href="http://eu.site6.com/index.html" target="_blank">https: // eu. evil. com</a> <-- MATCH
<a href="https://site7.com/">http://www.site7.com/123/test</a> <-- NOT MATCH
我开始写类似 this 的东西,但是我的代码在做相反的事情时遇到了问题。
帮我弄清楚如何制作我想要的东西。
您的原始表达式设计得很好,但我会使用一些语句,例如:
(?!.*.*)
或:
(?!((?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?()).*)
内,要绕过 url.text
中的相同域,可能使用类似于以下的一些表达式:
(?i)<a\s+href="(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?"[^>]*>(?!.*.*)(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?.*?<\/a>
或者更准确地说:
(?i)<a\s+href="(?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?([a-z0-9_-]+\.[a-z0-9_-]{2,6})(\/[^"]*)?"[^>]*>(?!((?:https?:\/\/)?(?:w{3}\.)?(?:[^"\/]*\.)?()).*)(?:https?:\s*\/\/\s*)?(?:\s*w{3}\.\s*)?(?:[^"\/]*\.\s*)?([a-z0-9_-]+\s*\.\s*[a-z0-9_-]{2,6}\s*)(\/[^"]*)?.*?<\/a>
您最有可能想要修改的内容,并更改边界。例如,您可以在任何您想要留出一些空格的地方添加 \s*
,或者使用双界量词 \s{0,5}
.
Demo
如果您希望 simplify/modify/explore 表达式,regex101.com. If you'd like, you can also watch in this link 的右上面板已经解释了它如何与一些样本输入相匹配。