Add constant value to numeric XML attribute
Posted
by
Dave Jarvis
on Super User
See other posts from Super User
or by Dave Jarvis
Published on 2011-01-14T19:57:42Z
Indexed on
2011/01/14
20:55 UTC
Read the original article
Hit count: 263
Background
Add a constant value to numbers matched with a regular expression, using vim (gvim).
Problem
The following regular expression will match width="32"
:
/width="\([0-9]\{2\}\)"
Question
How do you replace the numeric value of the width
attribute with the results from a mathematical expression that uses the attribute's value? For example, I would like to perform the following global replacement:
:%s/width="\([0-9]\{2\}\)"/width="\1+10"/g
That would produce width="42"
for width="32"
and width="105"
for width="95"
.
Thank you!
© Super User or respective owner