2016-06-10 92 views
4

正則表達式匹配雙引號我有串這樣的:不遵循斜槓字符

「ABCD \」 EFG \「喜」 JKLM」

我想這兩者之間的子串第一個字符",這是不\" 例如,在上面的字符串,我想abcd\" efg\" hi 目前,我被另一個字符替換\",然後使用正則表達式"([^"]*)"提取兩個FIR之間的子串st characters "。有沒有辦法直接使用正則表達式,而不用另一個字符替換\"

回答

3

使用這個表達式:

[^\\]?"(.*?[^\\])" 

說明:

[^\\]? match an optional single character which is not backslash 
"(.*? match a quote followed by anything (non-greedy) 
[^\\])" match a quote preceded by anything other than backslash 

此正則表達式匹配的開口報價和關閉報價不具有反斜槓之間的最小內容。

Regex101