bairui

Perl-ish Extended Regexes

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