I want to empty inner columns in a latex table, ie all the words between 2 &. How I can do it ? I have tried quite a few formulas like

s/&*&/\& \&/gc    

but I just can't find the right pattern to match. Thanks for your help.

  • could you provide an example? Original text vs Result text?
    – Maxim Kim
    Apr 24, 2020 at 13:16
  • 1
    You need an atom to repeat with *, eg, [^&]*
    – D. Ben Knoble
    Apr 24, 2020 at 14:12

1 Answer 1


Try it like this:

s/&\zs.\{-}\ze&/ /gc


  • & is the literal ampersand
  • \zs sets the start of the match
  • .\{-} matches any characters - but as few as possible
  • \ze sets the end of the match
  • & is the literal ampersand

There are two special things here=

First \zs...\ze: The part between them are the matched text, the ampersand before and after are just "anchors". This is important, as otherwise the matches would overlap like:

 &  This Stuff   &  Other Stuff  &
 |-- 1st match --|
                 |-- 2nd match --|

Second .\{-}: The dot matches any character and the \{-} defines zero or more matches, but as few as possible. The next character in the match is a &. So it matches zero or more chars until it finds a ampersand.

The replacement is just a simple whitespace, as we just replace the part between the ampersands.

  • Works like a charm. Thank you for the solution and the detailed explanations. Apr 26, 2020 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.