Reputation: 17
I have one string, I want to remove some repeated part from string using ajax or javascritp.
The string is -
1-16-15-master=1232_2-34-33-master=1232_3-33-23-master=1236
Above string is connect using underscore (_) sign. means above string include 3 string. I want to remove -master=122....
The '-master=' is default but after equal sign(=) number will change. So how to remove '-master=n...' from above string.
Upvotes: 0
Views: 69
Reputation: 3965
Try this:
var str = "1-16-15-master=1232_2-34-33-master=1232_3-33-23-master=1236";
str = str.replace(/-master=/g,'=');
Upvotes: 1
Reputation: 68790
Use a replace function with a greedy /-master=\d+/
regex :
PHP
$input = "1-16-15-master=1232_2-34-33-master=1232_3-33-23-master=1236";
$output = preg_replace('/-master=\d+/', '', $input);
echo $output; // 1-16-15_2-34-33_3-33-23
JS
var input = "1-16-15-master=1232_2-34-33-master=1232_3-33-23-master=1236";
var output = input.replace(/-master=\d+/g, '');
console.log(output); // 1-16-15_2-34-33_3-33-23
Upvotes: 2
Reputation: 3328
var s = "1-16-15-master=1232_2-34-33-master=1232_3-33-23-master=1236";
console.log(s.replace(/-master=\d+/g, ''));
Upvotes: 4