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

I have text stored in a variable, for example, for example:

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

How to check if text matches regular expression? I expect something like this:

 let text = getline(line(".")-1) if regexp_match(text, "^[Ss]tuff$") dostuff endif 
+4
source share
1 answer

I did some more research and found out that I need = ~ # operator , which is used to check if some text matches the regular expression:

 if "text"=~#"^te.." echo "Matches!" 
+6
source

Source: https://habr.com/ru/post/1437483/


All Articles