Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use regular expressions on variables with text in vimscript?

Tags:

regex

vim

I have text saved in a variable, for example, like this:

let text = getline(line(".")-1)

How do I check if the text matches a regular expression? I'm expecting something like this:

let text = getline(line(".")-1)
if regexp_match(text, "^[Ss]tuff$")
    dostuff
endif
like image 423
gvlasov Avatar asked Oct 02 '12 22:10

gvlasov


1 Answers

Made some more research and found out that what I needed is =~# operator which is used to check if some text matches a regexp:

if "text"=~#"^te.."
    echo "Matches!"
like image 90
gvlasov Avatar answered Nov 19 '22 12:11

gvlasov