1

Tried searching for regex found in this answer:

(,)(?=(?:[^']|'[^']*')*$)

I tried doing a search in Sublime and it worked out (around 700 results). When trying to replace the results it runs out of memory. Tried /(,)(?=(?:[^']|'[^']*')*$) in vim for searching first but it does not find any instances of the pattern. Also tried escaping all the ( and ) with \ in the regex.

Community
  • 1
  • 1
cabe56
  • 404
  • 2
  • 14

4 Answers4

3

Vim uses its own regular expression engine and syntax (which predates PCRE, by the way) so porting a regex from perl or some other editor will most likely need some work.

The many differences are too numerous to list in detail here but :help pattern and :help perl-patterns will help.

Anyway, this quick and dirty rewrite of your regular expression seems to work on the sample given in the linked question:

/\v(,)(\@=([^']|'[^']*')*$)

See :help \@= and :help \v.

romainl
  • 186,200
  • 21
  • 280
  • 313
1

One possible explanation is that the regular expression engine used in Sublime is different than the engine used in vim.

Not all regex engines are created equal; they don't all support the same features. (For example, a "negative lookahead" feature can be very powerful, but not all engines support it. And the syntax for some features differs betwen engines.)

A brief comparison of regular expression engines is available here:

http://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines

spencer7593
  • 106,611
  • 15
  • 112
  • 140
1

Unfortunately Vim uses a different engine, and "normal" regular expressions won't work. The regex you've mentioned isn't perfect: it doesn't skip escaped quotes, but, as I understand, it's good enough for you. Try this one, and if it doesn't match something, please send me that piece.

\v^([^']|'[^']*')*\zs,

A little explanation:

\v enables very magic search to avoid complex escaping rules

([^']|'[^']*') matches all symbols but quote and a pair of qoutes

\zs indicates the beginning of selection; you can think of it as of a replacement for lookbehind.

shock_one
  • 5,845
  • 3
  • 28
  • 39
0

You have to escape the |, otherwise it doesn't work under vim. You should also escape the round brackets, unless you are searching for the '(' or ')' characters.

More information on regex usage in vim can be found on vimregex.com.

miindlek
  • 3,523
  • 14
  • 25
  • I was already escaping the round brackets. Escaping the `|` didn't fix the issue. – cabe56 May 30 '14 at 16:09
  • 1
    @cabe56 If you read my link in the comments, VIM assertions are different, try `\(,\)\@=\([^']\|'[^']*'\)*$` – hwnd May 30 '14 at 16:10