用于从通用名称查找域的 SQL 正则表达式
我的一个表中有以下示例数据集:
sub1.domain.com
域名.com
sub1.sub2.domain.com
*.domain.com
已更新
还包括 ccTLD
*.domain.co.uk
Oracle 中有一种方法/正则表达式可以帮助我从字符串中提取域名 - “domain.com”。我一直在尝试一些正则表达式但它没有成功。 感谢您的帮助
I have the following sample data set in one of my tables:
sub1.domain.com
domain.com
sub1.sub2.domain.com
*.domain.com
Updated
Also including ccTLD
*.domain.co.uk
is there a way/regex in Oracle that can help me extract just the domain name - "domain.com" from the string.I have been trying a few regexes but it dint work out.
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下正则表达式从字符串末尾匹配something_without_a_dot.something_without_a_dot。您将在第一组中得到答案。如果您还需要 TLD,则可以将除
$
之外的所有内容括在()
中。在 SQL 中,这给出了:
开头的非贪婪
.*?
允许您忽略字符串的开头。要获取域名和 TLD:
考虑
, '\1') from dual; REGEXP_REPLA ------------ domain.co.uk , '\1') from dual; REGEXP ------ domainco.uk
:开头的非贪婪
.*?
允许您忽略字符串的开头。要获取域名和 TLD:
考虑
, '\1') from dual; REGEXP_REP ---------- domain.comco.uk
:考虑
, '\1') from dual; REGEXP ------ domainco.uk
:开头的非贪婪
.*?
允许您忽略字符串的开头。要获取域名和 TLD:
考虑
co.uk
:You could use the following regex matching something_without_a_dot.something_without_a_dot from the end of the string. You'll get the answer in the first group. If you need the TLD also, you can enclose everything in
()
except the$
.In SQL, that gives:
The non-greedy
.*?
at the start allows you to ignore the start of the string.To get the domain name plus the TLD:
To take into account
, '\1') from dual; REGEXP_REPLA ------------ domain.co.uk , '\1') from dual; REGEXP ------ domainco.uk
:The non-greedy
.*?
at the start allows you to ignore the start of the string.To get the domain name plus the TLD:
To take into account
, '\1') from dual; REGEXP_REP ---------- domain.comco.uk
:To take into account
, '\1') from dual; REGEXP ------ domainco.uk
:The non-greedy
.*?
at the start allows you to ignore the start of the string.To get the domain name plus the TLD:
To take into account
co.uk
:当我输入答案时,上面的人给出了一个很好的正则表达式。我认为您可以在 select 语句中使用 REGEXP_REPLACE 。
While I was typing my answer the guy above gave a good regex. I'm thinking you could use REGEXP_REPLACE in your select statement.