regex in vimscript

无人久伴 提交于 2019-12-18 12:54:33

问题


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.


回答1:


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 /\{-


来源:https://stackoverflow.com/questions/3135322/regex-in-vimscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!