NirMH
NirMH

Reputation: 4949

Vim regex to match a tab or space?

I would like to trim the following string:

<tab>PACKAGE MAIN (the string starts with a tab space)

The goal is to get only PACKAGE MAIN as an output.

I've tried the following VIM functions with arguments

let line = substitute (line, '\t+(.*)'      , '\1', 'g')
let line = substitute (line, '\t+\(.*\)'    , '\1', 'g')
let line = substitute (line, '\t\+\(.*\)'   , '\1', 'g')
let line = substitute (line, '[\s\t]+\(.*\)', '\1', 'g')

(and much more)

What is the guideline for VIM regex to match <tab> or <space> (whitespace) chars in the substitute function?

Upvotes: 5

Views: 12269

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18865

Modify slightly the last one:

substitute (line, '[ \t]\+\(.*\)', '\1', 'g')

+ must be prepend by \ in order to get the magic meaning. You can use \s for any whitespace instead of [ \t] which matches only space and tab.

Upvotes: 6

Related Questions