bairui

Perl-ish Extended Regexes

Sep 28th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.51 KB | None | 0 0
  1. " Perlish extended regexs
  2. " Barry Arthur, Sep 2011
  3.  
  4. " Comments must start with two spaces and end with space and _
  5.  
  6. function! R(s)
  7.   return substitute(substitute(a:s, '\s\{2,}".\{-}\s\+_', '', 'g'), '\s\+', '', 'g')
  8. endfunction
  9.  
  10. function! TestThis(str)
  11.   let my_extended_regex = '
  12.        \ ^       " start of line    _
  13.        \ \s*     " skip whitespace  _
  14.        \ "\w\+"  " first word       _
  15.        \'
  16.  return matchstr(a:str, R(my_extended_regex))
  17. endfunction
  18.  
  19. echo TestThis('"hello" world')
Advertisement
Add Comment
Please, Sign In to add comment