Search notes:

VIM regular expressions: match at specific columns only

" ..\vimscript\run_.bat column_n

redir > column_n.out

"            12345678901
let s:str = 'foo bar baz'

let s:matched = matchstr(s:str, '...\%8c')
echo '>' . s:matched . '<'
" >bar<

fu RegexpForPos(pos, regexp)

   return
   \ '\v'                .
   \ '%<'  . (a:pos + 1) . 'v' .
   \          a:regexp   .     
   \ '%>'  .  a:pos      . 'v'

endfu
                      1         2         3         4         5         6         7  
"            1234567890123456789012345678901234567890123456789012345678901234567890123
let s:str = '# abc-7-def etc #ghi-42-jkl, foo, bar and # yyy-19-zzz or #qqq-234567-rrr'

for s:pos in range(42, 55)

    let s:matched = matchstr(s:str, RegexpForPos(s:pos, '# *\w+-\d+-\w+'))

    echo s:pos . '  >' . s:matched . '<'

endfor
" 42  ><
" 43  ># yyy-19-zzz<
" 44  ># yyy-19-zzz<
" 45  ># yyy-19-zzz<
" 46  ># yyy-19-zzz<
" 47  ># yyy-19-zzz<
" 48  ># yyy-19-zzz<
" 49  ># yyy-19-zzz<
" 50  ># yyy-19-zzz<
" 51  ># yyy-19-zzz<
" 52  ># yyy-19-zzz<
" 53  ># yyy-19-zzz<
" 54  ># yyy-19-zzz<
" 55  ><

redir END
q
Github repository about-vim, path: /regular_expressions/column_n.vim

See also

regular expressions
VIM script

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758198753, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/regular_expressions/column_n(88): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78