PatIndex Pattern /Regex:如何匹配后跟 space 的点

PatIndex Pattern /Regex: How to match a dot followed by a space

Q1-PatIndex 模式正则表达式:如何匹配一个点后跟一个 space? Q2 -PatIndex 模式正则表达式:如何匹配一个点后跟两个 spaces?.

我想把它放在这里只得到目标内容

 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

你也可以尝试使用LIKE语句。

columnname LIKE '.  %'

编辑:

试试这个:

Select SUBSTRING(data, LEN(LEFT(data, CHARINDEX ('GOAL:', data))) , LEN(data) - LEN(LEFT(data, CHARINDEX ('GOAL:', data))) - LEN(RIGHT(data, LEN(data) - CHARINDEX ('.', data))) - 1)
From   @Temp 

这个怎么样:

简短说明:将 . 替换为 xml-tags 将 "split" 这个字符串与 "parts" 中的字符串一样多。 XML-value 方法将获取第一项的值,即第一个 .

之前的字符串
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 CAST('<x>' + REPLACE(SubString(Data,PATINDEX ('%GOAL%',Data), 8000),'. ','</x><x>') + '</x>' AS XML).value('x[1]','varchar(max)')
From   @Temp