gpt4 book ai didi

c# - 正则表达式检测连字符

转载 作者:太空狗 更新时间:2023-10-30 01:04:59 26 4
gpt4 key购买 nike

现场演示:http://regex101.com/r/wW6wC4


我正在尝试添加一个允许电子邮件地址的正则表达式:

asdf.asdf@test-dom-a.com

([\w+\.]+@[\w]{1,})(\.)([0-9a-zA-Z\.\-]{1,})
^---- Thought this would allow hyphens...

我在这里错过了什么?

最佳答案

您的模式要求连字符出现在句号之后。试试这个:

([\w+.]+@[\w-]{1,})(\.)([0-9a-zA-Z.-]+)

Demonstration

或者更简单地说:

([\w+.]+@[\w.-]+)

虽然第二个模式不要求地址的第二部分包含句点。

Demonstration

关于c# - 正则表达式检测连字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20615171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com