需要在正则需要帮助的帮助以使用正则提取域

发布于 2025-02-09 11:13:02 字数 417 浏览 1 评论 0原文

任何人都可以帮助编写一条正则提取以下域的提取域:

如果值为:

dns.google
x2.xdn.cbn.com
hello.1234.extra.net.com

那么我的正则应为我输出如下:

  • dns.google ----没有匹配
  • x2.xdn。 cbn.com ---提取cbn.com仅
  • hello.1234.extra.net.com -------------------------------------------仅提取net.com。

我尝试了负面的态度,但失败了。

示例:(?< = \。)。+

Can anyone help to write a regex to extract domains like below:

If values are:

dns.google
x2.xdn.cbn.com
hello.1234.extra.net.com

then my regex should give output to me as below:

  • dns.google --- no match
  • x2.xdn.cbn.com --- extracts cbn.com only
  • hello.1234.extra.net.com ---extracts net.com only.

I tried with negative lookbehind but failed.

Example: (?<=\.).+

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

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

发布评论

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

评论(1

抚笙 2025-02-16 11:13:03

假设您在一个名为domains.txt的文件中输入了输入,并且您想匹配每个域的最后两个部分,该域具有两个以上的部分,则基于GREP的解决方案可以看起来像这样:

grep -Po "[.]\K[^.]+[.][^.]+$" domains.txt

Assuming that you have your input in a file called domains.txt and you would like to match the last two parts of each domain which has more than two parts, a grep-based solution could look like this:

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