regex - Lists of Start and End Columns of all matches in a line -


i'm trying create list of start columns , list of end columns of matches in line.

this i've done:

line1:

test passed list "that" [passed]  

search: \<[a-za-z\x7f-\xff]\+\>
(find words)

commands:

let matchesstart = [] | 1s/\<[a-za-z\x7f-\xff]\+\>/\=add(matchesstart,match(getline(1),submatch(0)))/gn let matchesend = []   | 1s/\<[a-za-z\x7f-\xff]\+\>/\=add(matchesend,matchend(getline(1),submatch(0)))/gn 

results:

matchesstart = [0, 5, 8, 9, 18, 22, 26, 32, 5, 8, 9]
matchesend = [4, 7, 14, 11, 21, 25, 30, 36, 7, 14, 11]

the problem matches aren't unique. last word 'as' in line found in 'passed', last word 'is' not found because detected 2nd word in line, , on.

expected output:

matchesstart = [0, 5, 8, 15, 18, 22, 26, 32, 38, 42, 50]
matchesend = [4, 7, 14, 17, 21, 25, 30, 36, 40, 48, 52]

please see difference of entry 4, 9, 10 , 11.

how can create unique list of numbers of matches (from start end of line)?

update:

please search of \s\zs\p\w\+

to find start , endcolumn of match tried match/matchend

match = '31'
matchend = '-1'

searchpos gives correct startcolumn (32) doesn't give endcolumn.
cannot use matchend find endcolumn because start value wrong cause of '\s' before '\zs'

use searchpos() function search pattern, wrap in loop (while e.g.) if 2nd element in returned list 0, you've done search on line.

:h searchpos( read details.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -