PHP RegEx: How to Stripe Whitespace Between Two Strings
Posted
by roydukkey
on Stack Overflow
See other posts from Stack Overflow
or by roydukkey
Published on 2010-03-19T04:18:07Z
Indexed on
2010/03/19
4:21 UTC
Read the original article
Hit count: 296
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.
© Stack Overflow or respective owner