【发布时间】:2016-02-12 09:13:20
【问题描述】:
Q1-PatIndex 模式正则表达式:如何匹配点后跟空格? Q2 -PatIndex Pattern Regex:如何匹配一个点后跟两个空格?
我想把它放在这里只得到目标内容
Declare @Temp Table(Data VarChar(1000))
Insert Into @Temp Values('Lalallaa GOAL: This is the truthmeow. Meow. ')
Insert Into @Temp Values('Lalallaa GOAL: This is the truth. Meowrwr. ')
Insert Into @Temp Values('lALALLA GOAL: This is the truth. Meowrwr. NOTINCLUDED: WAWAW')
Select Left(
SubString(Data,PATINDEX ('%GOAL%',Data), 8000) ,
PatIndex('regex here', SubString(Data, PatIndex('%[GOAL]%', Data), 8000))-1)
From @Temp
预期输出
GOAL: This is the truthmeow.
GOAL: This is the truth.
GOAL: This is the truth.
我在真实数据库上使用了 Shnugos 答案,但遇到了错误:Illegal name character
我检查了数据类型,是ntext
【问题讨论】:
-
\.\s(Q1) 或\.\s{2}(Q2)。罗杰出去 :) -
在广阔的世界中有大量的教程和在线测试表格。 SO 不是作业平台...
-
预期输出是什么?
-
更新问题@RahulTripathi
-
@PhilipMorris:- 更新了我的答案。请检查。
标签: sql-server regex patindex