![](/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.