Sergei Zahharenko
Sergei Zahharenko

Reputation: 1524

Regex/Replace any chars inside match combination

For example

var string = 'width="300" height="650"'

i would like to update height in that string and get something like

string = string.replace(/height="..."/g, 'height="150"');
//... as any symbol

how to make reg expression who does not care value of height, to replace it with new one?

You can play with it here, in example: JsFiddle

Upvotes: 0

Views: 180

Answers (2)

Erez
Erez

Reputation: 2655

for case insensitive use:

.replace(new RegExp(/height=\"[0-9]+\"/gi), 'height="150"');

Upvotes: 2

Ricardo Lohmann
Ricardo Lohmann

Reputation: 26320

var string = 'width="300" height="650"';
string = string.replace(new RegExp(/height=\"[0-9]+\"/g), 'height="150"');

DEMO

Upvotes: 4

Related Questions