Regex将冒号替换为冒号和分号之间的冒号

时间:2021-12-14 11:08:54

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 this is the case, I want to replace the colon in the middle.

例如,我想确定以下内容中有:in between: and;如果是这样的话,我想要替换中间的冒号。

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

背景图片: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?

我无法为我的生活想出一个正则表达式。我只能匹配整个url('http://google.com/img.jpg')。我可以用什么regex为我做这个?

$pattern = ''; 

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

1 个解决方案

#1


3  

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

#1


3  

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