Search code examples
regexvimviml

regex in vimscript


let test = 'a href="http://www.google.com">www.google.com</a;'

In vimscript, how can I get http://www.google.com out of this using a regexp, and store it in another variable?

I can't seem to find any documentation about this.


Solution

  • let url = matchstr(test, '\ca href=\([''"]\)\zs.\{-}\ze\1')
    if empty(url) 
       throw "no url recognized into ``".test."''"
    endif
    

    For more information, see:

    :h matchstr()
    :h /\c
    :h /\zs
    :h /\{-