我需要正则表达式来获取子串

时间:2014-12-10 14:23:19

标签: regex

Started transaction at 10.12.2014 16:11:02 +02:00
UPDATE [dbo].[Urun]
SET [Ad] = @0, [Kategori] = @1
WHERE ([Id] = @2)

-- @0: 'Erkan' (Type = String, Size = 75)

-- @1: 'Karabulut' (Type = String, Size = 50)

-- @2: '1' (Type = String, Size = 25)

-- Executing asynchronously at 10.12.2014 16:11:02 +02:00

-- Completed in 4 ms with result: 1

Committed transaction at 10.12.2014 16:11:02 +02:00

这是我的字符串。我在[dbo]之后首先需要子串。意味着需要表名和第二个日期时间。我需要正则表达式。

输出

"Urun" and "10.12.2014 16:11:02 +02:00"

感谢您的帮助...

1 个答案:

答案 0 :(得分:0)

使用以下正则表达式并从组索引1和2中获取所需的字符串。

(?s)\[dbo\].*?\[([^\]]*)\].*?\d{2}\.\d{2}\.\d{4}\s+\d{2}:\d{2}:\d{2}.*?\b(\d{2}\.\d{4}\s+\d{2}:\d{2}:\d{2}\s+\S+)

DEMO

添加了alernative,因为我不知道你的日期和时间。

(?s)\[dbo\].*?\[([^\]]*)\].*?\b(\d{2}\.\d{2}\.\d{4}\s+\d{2}:\d{2}:\d{2}\s+\S+)

DEMO

(?s) Dotall修饰符,使你的正则表达式中的点匹配偶数换行符。

相关问题