2016-11-17 54 views
0

我想寫一個(Ruby)正則表達式來捕獲關閉EViews字符串的雙引號。在的EViews,字符串用雙引號,幷包含一個字符串實際雙引號,我們雙寫雙引號:查找最後一個「字符串在哪裏」被寫爲「」

myStr = "item1 item2 item3" 
myStr2 = """item1"" ""item2"" ""item3""" 

字符串可以出現在任何地方的線路,所以我不使用開始幫助和線的結尾。

我至今是:

((?<="")|(?<!"))(")(?!") 

也就是說,發現通過以下兩種雙引號或沒有雙引號前面,而不是由一個雙引號成功一個雙引號。這抓住了最後的雙引號,但不幸的是開幕式。

在一個側面說明,我需要這樣的原因是,我與描述爲崇高的文本3的EViews語法捕捉串YAML文件的工作,這是我迄今:

strings: 
    - match: '"' 
    scope: punctuation.definition.string.begin.eviews 
    push: string 

string: 
    - meta_scope: string.quoted.double.eviews 
    - match: '"' #((?<="")|(?<!"))(")(?!") 
    scope: punctuation.definition.string.end.eviews 
    pop: true 
+1

你可能會用''[^「] –

回答

0

這個問題可能不是最好的方式。我最終提出了一個可能有點笨拙的解決方案,但它的工作原理如下:

strings: 
    - match: '"' 
    scope: punctuation.definition.string.begin.eviews 
    push: string 

string: 
    - meta_scope: string.quoted.double.eviews 
    - match: '""' 
    - match: '"' 
    scope: punctuation.definition.string.end.eviews 
    pop: true 
相關問題