PHP RegEx: How to Stripe Whitespace Between Two Strings
- by roydukkey
I have been trying to write a regex that will remove whitespace following a semicolon (';') when it is between both an open and close curly brace ('{','}'). I've gotten somewhere but haven't been able to pull it off. Here what I've got:
<?php
$output = '@import url("/home/style/nav.css");
body{color:#777;
background:#222 url("/home/style/nav.css") top center no-repeat;
line-height:23px;
font-family:Arial,Times,serif;
font-size:13px}'
$output = preg_replace("#({.*;) \s* (.*[^;]})#x", "$1$2", $output);
?>
The the $output should be as follows. Also, notice that the first semicolon in the string still is followed by whitespace, as it should be.
<?php
$output = '@import url("/home/style/nav.css");
body{color:#777;background:#222 url("/home/style/nav.css") top center no-repeat;line-height:23px;font-family:Arial,Times,serif;font-size:13px}';
?>
Thanks! In advance to anyone willing to give it a shot.