File contains following line:
[assembly: AssemblyVersion("1.0.0.0")]
Bash script that replaces one version to another:
echo "%s/AssemblyVersion\s*\(.*\)/AssemblyVersion(\"$newVersionNumber\")]/g
w
q
" | ex $filePath
The question is why this catch whole line to the end so i have to add ] at the end of replacement string?
The problem arises because
.*matches all the chars to the end of the line, and\(and\)create a capturing group (unlike most of NFA regex engines, Vim regex matches a(char with an unescaped(and)with an unescaped)in the pattern).You may use
Here,
AssemblyVersionwill match the word, then\s*will match any 0+ whitespace chars,(will match a literal(,[^()]*will match 0+ chars other than(and), and)will match a literal).Another regex substitution command you may use is
Here,
AssemblyVersion\s*(will matchAssemblyVersion, 0+ whitespaces and(and\zswill omit that part from the match, then 0+ chars other than(and)will get matched, and then\ze)will check if there is)to the right of the current location, but won't add it to the match.\zssets the next character to be the first character of the match. Any text before the\zspattern will not be included into the match.\zesets the end of the match. Anything after the\zspattern will not be part of the match.