regex 正则表达式匹配域扩展

mv1qrgav  于 2022-11-18  发布在  其他
关注(0)|答案(2)|浏览(238)

我需要确认域扩展是否存在。
到目前为止,我还无法获得域扩展名的匹配项
域名可以有通配符的地方:请访问:gmail.com、msn.com、mac.com、comcast.net

DomainPartOfEmail = Right(temp, (Len(temp) - temp.LastIndexOf("@") - 1))
    If Regex.IsMatch(DomainPartOfEmail, "*.edu? | *.com? | *.net? | *.org?", RegexOptions.IgnoreCase) Then
        ValidDomain = True
    End If
nbnkbykc

nbnkbykc1#

如果域名仅来自这些(edu、com、net、org),则使用以下域名:

".*\.(edu|com|net|org)$"

正则表达式的解释:

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  \.                       '.'
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    edu                      'edu'
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    com                      'com'
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    net                      'net'
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    org                      'org'
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
5q4ezhmt

5q4ezhmt2#

实际上,给出的答案遗漏了诸如something.org/default.html之类的url。因此,为了解决这个问题,我建议使用下面的正则表达式模式:

.*\.(edu|com|net|org)(/.*|$)

您可以测试here

相关问题