I am trying to remove leading and trailing spaces in a function but it does not work:
function Trim(s)
echo ">>>".a:s."<<<"
let ss = substitute(a:s, '\v^\s*([^\s]+)\s*$', '\1', '')
echo ">>>".ss."<<<"
endfunction
The regex \s*([^\s]+)\s*
works ok on https://regex101.com/
Replacing * with + does not make any difference.
Testing:
: call Trim(" testing ")
Output:
>>> testing <<<
>>> testing <<<
Also it seems to matter if I use double quotes versus single quotes in substitute function.
Where are the problems and how can they be solved? Thanks.