3

Saying that I have such a file as below:

<random_string>hello<random_string>
random_string<random_string>hello<random_string>

I want to remove the first square bracket and its content so that the file becomes:

hello<random_string>
random_stringhello<random_string>

How could I achieve this?

I've tried to execute :%s/<.*>// but it will remove all things I think it's because it matches the last > for each line.

Yves
  • 1,013
  • 1
  • 10
  • 25

1 Answers1

4

I guess this would be the easiest solution:

%s/<[^>]*>//

It matches:

  • < an opening angle bracket
  • [^>]* anything not being a closing angle bracket
  • > a angle bracket.

Of course the other solution is to use a non greedy operator as in the question linked by @Mass like this:

%s/<.\{-}>//
Ralf
  • 9,197
  • 1
  • 11
  • 30
statox
  • 49,782
  • 19
  • 148
  • 225