如何从 MS SQL 中的文本/varchar 中选择正则表达式匹配? [英] How do I select a regex match from a text/varchar in MS SQL?

查看:32
本文介绍了如何从 MS SQL 中的文本/varchar 中选择正则表达式匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 Microsoft SQL Server 数据库中跨多个 db 行的长文本中提取一些内容.

I need to extract something from a long piece of text across lots of db rows, in a Microsoft SQL Server database.

我可以编写一个脚本来循环并提取它,但我希望有一种很好的简单方法可以执行一些 SQL,例如:

I could write a script to loop through and extract it, but I was hoping there was nice simple way I can do some SQL like:

SELECT IpAddress = matchFirst('RegEx',ColName)
FROM table
WHERE conditions


我已经看过了,但我发现的只是关于在 where 子句和 CLR UDF 中使用正则表达式和其他东西的不清楚的冗长杂谈 - 但我想要的只是一个简单的在此处插入正则表达式"的答案.


I've looked about but all I'm finding is unclear long-winded ramblings about using regex in the where clause and CLR UDFs and stuff - but all I want is a simple "insert regex here" answer.

有什么想法吗?

推荐答案

如果您正在寻找一个简单的解决方案,我建议您使用 SQL# 库,它基本上包含您需要的 UDF,您会在其他地方找到引用.

If you're looking for a simple solution I would suggest using the SQL# library which basically contains the UDF you need and you'll find referenced elsewhere.

安装后(安装起来相当轻松),您会发现一个名为 RegEx_MatchSimple 的函数,我认为这正是您所需要的.

Once that's installed (it's reasonably painless to install) you will find a function called RegEx_MatchSimple which I believe is what you need.

这篇关于如何从 MS SQL 中的文本/varchar 中选择正则表达式匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆