开发者

Regex replace the colon in between a colon and a semi-colon

开发者 https://www.devze.com 2023-03-25 16:32 出处:网络
Given a string, how can I identify the string has a colon in between a colon and a semi-colon? For example, I want to identify that the following has a : in between : and ;. If t开发者_开发百科his is

Given a string, how can I identify the string has a colon in between a colon and a semi-colon?

For example, I want to identify that the following has a : in between : and ;. If t开发者_开发百科his is the case, I want to replace the colon in the middle.

background-image: url('http://google.com/img.jpg');"

I can't come up with a regex for the life of me. I can only match the whole url('http://google.com/img.jpg'). What regex can I use that can do this for me?

$pattern = ''; 

$matched = preg_replace($pattern, '|__|', $string);


$pattern = '/(:.*?):(.*?;)/s';
$matched = preg_replace($pattern, '$1|__|$2', $string);
0

精彩评论

暂无评论...
验证码 换一张
取 消