简体   繁体   中英

Find last “ in strings where ” are written as “”

I'm trying to write a (Ruby) regex for capturing the double quote that closes an EViews string. In EViews, strings are enclosed by double quotes and to include actual double quotes in a string, we write double double quotes:

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

Strings can appear wherever on a line, so I'm not helped by using beginnings and endings of lines.

What I have so far is:

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

That is, find a double quote that is preceded by either two double quotes or no double quote and is not succeeded by a double quote. This captures the closing double quote, but sadly also the opening one.

On a side note, the reason that I need this is that I'm working with a YAML file describing EViews syntax for Sublime Text 3. As for capturing strings, this is what I have thus far:

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

This question was perhaps not phrased in the best way. I ended up with a solution that perhaps is a bit clumsy, but works:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM