正则表达式将JSON属性值包装在另一个字符串中

时间:2015-10-08 05:56:55

标签: regex

{ "url": "products/Sensors.html",
  "thumbnailUrl":"/images/icons/no_image.png",
  "translatedTitle": "sensors",
  ...
},
...

我想将附加值“localhost:8080”添加到属性“thumbnailUrl”,以.png | jpg等结尾

替换值应为:

{ "url": "products/Sensors.html",
  "thumbnailUrl":"localhost:8080/images/icons/no_image.png",
  "translatedTitle": "sensors",
  ...
}

1 个答案:

答案 0 :(得分:0)

为什么不这样做     Myobj.thumbnailUrl =" localhost:8080" + myobj.thumbnailUrl;

否则     Mynewstring = myexistingstring.replace(/(thumbnailUrl \":\")/,' $ 1' +' localhost:8080');