Abs
Abs

Reputation: 57926

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

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.

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);

Upvotes: 2

Views: 1732

Answers (1)

Karolis
Karolis

Reputation: 9562

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

Upvotes: 3

Related Questions