-1
var someString = "style="height: 247px; width: 329px;" rel="height: 247px; width: 329px;" ";

how to update width value from 329px to 500px using regular expression in javascript.

i'm able to get the width value by using

reg = /width:\s(\d*)/;
someString.match(reg)[1];

but how to update all width values ?

ida
  • 545
  • 2
  • 5
  • 20

1 Answers1

1
var someString = "style=\"height: 247px; width: 329px;\" rel=\"height: 247px; width: 329px;\" ";
someString.replace(/width:\s(\d*px)/g,'500px')

I am correcting a bit:

someString.replace(/width:\s(\d*px)/g,'width: 500px')

Here is example: Click Here.

Dee Nix
  • 170
  • 1
  • 13
Piyush.kapoor
  • 6,715
  • 1
  • 21
  • 21