match() to get the offsets of all matches of a pattern in a string

8 views
Skip to first unread message

BPJ

unread,
Jul 28, 2015, 12:03:01 PM7/28/15
to vim...@googlegroups.com
I have a string of rows of dashes alternating with spaces,
where the number of dashes/spaces is variable

----- ------- --- ----

I want to get a List of the offsets of all the space sequences,
kind of a match() with /g (that's the best I can do to describe
it...) In the case above (ignoring the indent, I would get
[6, 16, 20].

It's the usual problem: I don't know the right :help keyword

/bpj

BPJ

unread,
Jul 28, 2015, 12:56:20 PM7/28/15
to vim...@googlegroups.com
Sorry for the noise. I gave up and did it the traditional way:

let colpos_l = []
let colpos = 0
let str_len = strlen(line)
while colpos < str_len
let colpos = matchend(sepline, '-\+\ze\s', colpos)
if colpos < 0
break
elseif colpos > 0
" call add(colpos_l, colpos)
call add(colpos_l, colpos)
endif
endwhile

I will make a 'plugin' of a generalized version of this though...

Reply all
Reply to author
Forward
0 new messages