0

I have a string like:

{
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
    { SomeTextNoQuotes, "Some Text's", "Some Text" },
}

How can I match the last , "Some Text" of each row, just before the }? By the way, this is in Sublime Text that I'm trying to do it. The values are not consistent like I have them here, and I have a few hundred lines to replace on.

I tried , ".*" but that matches , "Some Text's, "Some Text".

user1960364
  • 1,951
  • 6
  • 28
  • 47

3 Answers3

1

I don't use Sublime Text, but if it supports lookaheads, , ".[^"]*"(?= }) should do the trick.

Amadan
  • 191,408
  • 23
  • 240
  • 301
1

A few ways you could go about this.

Option #1 we match the first set and then capture the second including the comma in group \1 or $1

"[^"]*"(, "[^"]*")

See live demo

Option #2 we use a look ahead to find that matched set.

, "[^"]*"(?= \})

See live demo

Option #3 we can match the whole string and our match is included in capture group \1 or $1

\{[\S\s]*?(,\s+"[^"]*")\s+\}

See live demo

hwnd
  • 69,796
  • 4
  • 95
  • 132
  • #2 worked perfect, not sure how to use groups in sublimes replace. But a big +1 for those live demos and that site, I've never seen it before but it looks like a great way to finally learn regexs! – user1960364 Oct 16 '13 at 02:25
  • 1
    See http://stackoverflow.com/questions/11819886/regular-expression-search-replace-in-sublime-text-2 for future reference on capture groups with replacing. – hwnd Oct 16 '13 at 02:31
0

The following should work (using lookahead):

("Some Text")(?= \}\,)

The captured text will be found in the first matched group

Link to Fiddle

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129