regex - Are there any cases when submatch(0) would not work in vim regexp replace? -


i have following source data, on attempting perform global replace via vim's regexp search , replace:

      "text": [{         "uid": "...",         "left": 50,         "top": 715,         "minsize": 60,         "maxsize": 70,         "width": "345px",         "align": "center",         "font": "...",         "forbidden": "",         "border": true,         "printtype": 0       } 

my search/replace string looks like:

:%s/"left": \(\d\+\)/"left": \=submatch(1)*0.66/g

effectively, attempting reduce "left" property 66% of current value, in cases.

unfortunately, resulting string becomes:

      "text": [{         "uid": "...",         "left": =submatch(1)*0.66,         "top": 715,         "minsize": 60,         "maxsize": 70,         "width": "345px",         "align": "center",         "font": "...",         "forbidden": "",         "border": true,         "printtype" 

so, instead of getting "left": 33 "left": =submatch(1)*0.66.

at first, thought because using =submatch(0). however, switching =submatch(0) didn't fix problem, , returned =submatch(0) in replaced string.

would there cases in expression wouldn't evaluated correctly?

when using expression in replacement replacement must start \= , rest evaluated expression. in case escaped equals sign.

the easiest way use \zs start match right before number

:%s/"left": \zs\d\+/\=submatch(0) * 0.66 

and use submatch(0) whole match, in case number.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -