2

Javascript REgExp. I want remove all words on the line after : to , Names of the properties must stay. I tryed this

var sostavRegexp = $(".post .sostav_box").text();
sostavRegexp = sostavRegexp.replace(/:(.*),*/, ' aaaaaaa');
alert(sostavRegexp);

But this changed all words in line from first ":" in line to last "," in line to one word "aaaaaaa".

I have this line

Мука: 200гр, Сахар: 200гр, Маргарин: 100гр,

Need this:

Мука, Сахар, Маргарин

I`m designer, not a programmer. Help me please :)

4

1 回答 1

0

使用不情愿/懒惰的量词。这将在第一个,之后:而不是最后一个之间进行匹配。

// g is for global replace
.replace(/:.*?,/g, ",")
于 2013-10-02T21:09:36.147 回答