I have a variable called $value that contains a string with a css expression. It can be a value or a function:
rgb( 25, 128, 128 );, transform( -50% -50% );, bottom 50px right 100px;, #198080;, bold;, 1px solid red;
I want to be able to identify if the expression contains a function or a string
$real_value = (is_numeric($value)) ?
$value :
(is_string($value) ?
(preg_match('/^\w/', $value) ? $value : '"' . $value . '"') :
'"'. $value . '"');
The idea is to assign to $real_value the value inside quotation marks like this: "#198080"; or this "bottom 50px right 100px"; but if it is a function, just return the same expression.
I started creating my regular expression, but I can't go past the first parentheses without breaking it: /^\w\-?\w?\(/
So I need to create a regular expression that checks if the string has the structure of a css function. There are not many of them (https://www.w3schools.com/cssref/css_functions.php) or just write one that checks for the parentheses
\b(?:attr|calc|conic-gradient|counter|cubic-bezier|hsla?|max|min|(?:(?:linear|radial)|repeating-(?:conic|linear|radial))-gradient|rgba?|var)\([^()]*\);?and then extend the list if needed regex101.com/r/OER19M/1str_contains. There’s definitely exceptions, for instance with thecontentproperty, but those would then start with a quote of some sort.