[英]Regex to match all words in qoutes
我正在嘗試編寫正則表達式來匹配作為sql過程調用的參數傳遞的所有單詞。
輸入ex:
exec GetNextSequence 'abc', @brokerId out, 'fds'
insert into [ttt](id, code, description, startDate, endDate)
values (@bid, @code, @code, getdate(), '099999')
....
所以我需要得到'abc'和'fds'。
你能幫我寫一下正則表達式,讓它們介於“EXEC(UTE)?”之間嗎? 和第一個關鍵字? 我擁有的關鍵字列表,所以如果你幫我使用INSERT就可以,我會替換它。
這個正則表達式將執行以下操作:
exec
關鍵字后第一行上的所有引用單詞 筆記
insert
作為錨點。 考慮這個字符串邊緣情況: exec GetNextSequence 'abc', @Insert, @brokerId out, 'fds'
(?<=^exec.*?)
假設您正在使用.net Regex引擎,因為許多語言不支持lookbehinds中的重復字符。 正則表達式
(?<=^exec.*?)'((?:(?!'|\n).)*)'
NODE EXPLANATION
--------------------------------------------------------------------------------
(?<= look behind to see if there is:
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
exec 'exec'
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
' single quote character
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
' single quote character
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
\n '\n' (newline)
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
. any character
--------------------------------------------------------------------------------
)* end of grouping
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
' single quote character
示范文本
exec GetNextSequence 'abc', @brokerId out, 'fds'
insert into [ttt](id, code, description, startDate, endDate)
values (@bid, @code, @code, getdate(), '099999')
樣本捕獲組
[0][0] = 'abc'
[0][1] = abc
[1][0] = 'fds'
[1][1] = fds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.