Automattic\WooCommerce\Vendor\Pelago\Emogrifier\HtmlProcessor

CssVariableEvaluator::replaceVariablesInPropertyValueprivateWC 1.0

Regular expression based on {@see https://stackoverflow.com/a/54143883/2511031 a StackOverflow answer}.

Method of the class: CssVariableEvaluator{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->replaceVariablesInPropertyValue( $propertyValue ): string;
$propertyValue(string) (required)
.

CssVariableEvaluator::replaceVariablesInPropertyValue() code WC 10.8.1

private function replaceVariablesInPropertyValue(string $propertyValue): string
{
    return (new Preg())->replaceCallback(
        '/
            var\\(
                \\s*+
                # capture variable name including `--` prefix
                (
                    --[^\\s\\),]++
                )
                \\s*+
                # capture optional fallback value
                (?:
                    # capture separator to confirm there is a fallback value
                    (,)\\s*
                    # begin capture with named group that can be used recursively
                    (?<recursable>
                        # begin named group to match sequence without parentheses, except in strings
                        (?<noparentheses>
                            # repeated zero or more times:
                            (?:
                                # sequence without parentheses or quotes
                                [^\\(\\)\'"]++
                                |
                                # string in double quotes
                                "(?>[^"\\\\]++|\\\\.)*"
                                |
                                # string in single quotes
                                \'(?>[^\'\\\\]++|\\\\.)*\'
                            )*+
                        )
                        # repeated zero or more times:
                        (?:
                            # sequence in parentheses
                            \\(
                                # using the named recursable pattern
                                (?&recursable)
                            \\)
                            # sequence without parentheses, except in strings
                            (?&noparentheses)
                        )*+
                    )
                )?+
            \\)
        /x',
        \Closure::fromCallable([$this, 'getPropertyValueReplacement']),
        $propertyValue
    );
}