I'm looking for a regular expression for use with PHP's preg_match_all()
function, which will give me all of the px
values from a CSS file.
For example, if the css below is used, then the expected result would be an array of:
array ( "11px", "0.45px", "11.0005px", "1.1px", "888.888px" )
The $pattern
string is what I have so far -- it doesn't appear to work, however.
The logic I was trying to use is: the number before the decimal can be up to 4 digits, the decimal symbol is optional, and the number after the decimal is optional, up to 4 digits, followed by "px".
$pattern = "/([0-9]{1,4}\.*[0-9]{1,4}*px)/";
$css = '
.some_class {
font-size: 11px;
margin-left: 0.45px;
margin-top:11.0005px;
border: 1.1px solid blue;
}
.another_class {
background: rgba(0, 0, 0, 0.2);
width: 100%;
color: #012345;
z-index: 12;
font-size: calc(100% + 888.888px);
}
';
preg_match_all($pattern, $css, $matches, PREG_PATTERN_ORDER);