vimscript 中的正则表达式 [英] regex in vimscript

查看:33
本文介绍了vimscript 中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在 vimscript 中,如何使用正则表达式从中获取 http://www.google.com,并将其存储在另一个变量中?

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.

推荐答案

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

这篇关于vimscript 中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆