user3030853
user3030853

Reputation: 17

how to remove particular repeated string from large string

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

Answers (3)

Ringo
Ringo

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

zessx
zessx

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

bagonyi
bagonyi

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

Related Questions