5

I have this regex

^\([^\t]*\)\t\([^\t]*\)\t\([^\t]*\)$

which is supposed to match

  1. beginning of the line
  2. a capture of all letter until a Tab
  3. a capture of all letter until a Tab
  4. a capture of all letter until a Tab
  5. the EOL

In Vim, this works fine: correct regex capture

But in Sublime it will not match. Why?

Community
  • 1
  • 1
New Alexandria
  • 6,951
  • 4
  • 57
  • 77

1 Answers1

5

Vim regex is rather specific and differs from the PCRE regex engine expression syntax that Sublime Text 3 uses.

In Sublime Text 3, you can write the pattern you used in Vim as

^([^\t\r\n]*)\t([^\t\r\n]*)\t([^\t\r\n]*)$

See the regex demo

In short, (...) should be used to form a capturing group, and you need to add \r\n to disallow a negated character class to match across lines (in Vim, [^.]* won't match a line break, but it will in Sublime Text 3).

Note that (...) (and not \(...\)) can also be used as a capturing group in Vim, but you need to use very magic mode to use that syntax.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563