DasOhmoff San
DasOhmoff San

Reputation: 975

Vim split string by multiple delimiters

is there a way to split a vimscript string with multiple delimiters? I know for example this will split the string by every '/':

split('C:/test/blub\bla\bla\bla.txt', '/').

But is there a way to split the string with multiple delimiters?

For example: split('C:/test/blub\bla\bla\bla.txt', ['/', '\'])

To split the string by every '/' and '\'.

Is there a way to do this?

Upvotes: 1

Views: 2787

Answers (1)

Amadan
Amadan

Reputation: 198324

split takes a regular expression pattern, so, using a character class ([...]):

split('C:/test/blub\bla\bla\bla.txt', '[/\\]') # double backslash in pattern

or using alternation (...\|...):

split('C:/test/blub\bla\bla\bla.txt', '/\|\')

Upvotes: 6

Related Questions