Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace string with a particular format

I have a string with the following format,

 some_string%value1:value2:value3:%some_anather_string%value4:value5:value6:%

I need to remove%value1:value2:value3:% and %value4:value5:value6:% from the string,i mean i need to remove any string with the format of starting with % ending with :% and values seperated with :

Is this possible?

I try with str_replace(),But it work only we know the values.

like image 929
Shijin TR Avatar asked Jul 12 '26 10:07

Shijin TR


1 Answers

Use can use this simple regex

echo $str = preg_replace("~%(.*?):%~","", $str);

Demonstration

like image 151
Shankar Narayana Damodaran Avatar answered Jul 14 '26 23:07

Shankar Narayana Damodaran