![](/img/trans.png)
[英]Can I find frequently occuring phrases in an array of strings where the phrase only forms part of each string?
[英]Find last “ in strings where ” are written as “”
我正在嘗試編寫一個(Ruby)正則表達式來捕獲關閉EViews字符串的雙引號。 在EViews中,字符串用雙引號引起來,並且為了在字符串中包含實際的雙引號,我們編寫雙雙引號:
myStr = "item1 item2 item3"
myStr2 = """item1"" ""item2"" ""item3"""
字符串可以出現在一行中的任何位置,因此使用行的開頭和結尾對我沒有幫助。
到目前為止,我有:
((?<="")|(?<!"))(")(?!")
即,找到一個雙引號,該雙引號前面有兩個雙引號或沒有雙引號,並且后沒有雙引號。 這捕獲了結尾的雙引號,但令人遺憾的是開頭的雙引號。
附帶說明一下,我需要這樣做的原因是我正在使用一個YAML文件,該文件描述了Sublime Text 3的EViews語法。至於捕獲字符串,這就是我到目前為止所擁有的:
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
這個問題也許不是用最好的方式表達的。 我最終得到了一個可能有點笨拙但可以解決的解決方案:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.