所有逃脱的一切正则排除组(\ r,\ n)

发布于 2025-01-19 08:25:18 字数 1545 浏览 5 评论 0原文

我尝试制作一条正则是从一些大文本文件中提取邮件地址。不幸的是,正则表达式也与逃脱的角色相匹配。我无法弄清楚如何配置这样的通用正则排除组。

REGEX:

([A-Za-z0-9]+[.\-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(.[A-Z|a-z]{2,})+

flags:“ simg”

示例文本:

 <i><b>[email protected]</b></i></a>
ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

REGEX匹配“ email&nbsp; >“而不是”

您可以在这里尝试一下我们: https://regex101.com/r/97imes/1

I try to make a regex to extract mail addresses from some big text files. Unfortunately the regex also matches on escaped characters. I can not figure out how to configure such a generic regex exclusion group.

Regex:

([A-Za-z0-9]+[.\-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(.[A-Z|a-z]{2,})+

Flags: "simg"

Example Text:

 <i><b>[email protected]</b></i></a>
ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

Regex matches "[email protected]" instead of "[email protected]".

You can try it our here: https://regex101.com/r/97ImeS/1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧竹 2025-01-26 08:25:18

可能的解决方案是以下解决方案,以防您想使用Python:

import re

string = """ <i><b>[email protected]</b></i></a>
ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n"""

string = string.replace('\s', '\r')

re_pattern = re.compile("[>\r\n]([a-z0-9.-]+@[a-z]+\.[a-z]{2})", re.I|re.M)
# 0-9 is not required for your example string

found = re_pattern.findall(string)

print(found)

打印:

['[email protected]',
 '[email protected]',
 '[email protected]',
 '[email protected]',
 '[email protected]']

REGEX模式说明:

”在此处输入图像描述”

Possible solution is the following in case you wanna use python:

import re

string = """ <i><b>[email protected]</b></i></a>
ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n

ОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\nОМ ПО ЭЛ. ПОЧТЕ: \[email protected]\r.\r\n"""

string = string.replace('\s', '\r')

re_pattern = re.compile("[>\r\n]([a-z0-9.-]+@[a-z]+\.[a-z]{2})", re.I|re.M)
# 0-9 is not required for your example string

found = re_pattern.findall(string)

print(found)

Prints:

['[email protected]',
 '[email protected]',
 '[email protected]',
 '[email protected]',
 '[email protected]']

Regex pattern explanation:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文