Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex in vimscript

Tags:

regex

vim

viml

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.

like image 420
guest Avatar asked Jun 28 '10 19:06

guest


People also ask

Does Vim search support regex?

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 )

Does VI support regex?

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.


1 Answers

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 /\{-
like image 184
Luc Hermitte Avatar answered Oct 01 '22 19:10

Luc Hermitte