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.
Using Regex in VimMany of Vim's search features allow you to use regular expressions. Some of them are: The search commands ( / and ? ) The global and substitute command-line (ex) commands ( :g and :s )
vi Regular Expressions(period) Matches any single character except a newline. Remember that spaces are treated as characters. Matches zero or more (as many as there are) of the single character that immediately precedes it. The * can follow a metacharacter, such as . , or a range in brackets.
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 /\{-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With