- preg_replace_callback: documentation ( source)
- preg_match: documentation ( source)
<?php
$string = 'a{ra:calc(*(la)100%);font-s';
$string_regex = '((?<!\\\\)(?:\\\\\\\\)*(\'|")(?:.*?[^\\\\])??(?:\\\\\\\\)*\\2)';
$comment_regex = '(\\/\\*(?:(?!\\*\\/).)*\\*\\/)';
$url_regex = '(?<=:| |,|\\(|\\))(url)\\s*(\\()\\s*((?:[^()]+|(?2))*?)\\s*(\\))';
$calc_regex = '(?<=:| |,|\\(|\\))(calc)\\s*(\\()\\s*((?:[^()]+|(?2))*?)\\s*(\\))';
$string = preg_replace_callback('/'.$string_regex.'|'.$comment_regex.'|'.$url_regex.'|'.$calc_regex.'/si', array(&$this, 'filter_callback'), $string);
$string = preg_match('/'.$string_regex.'|'.$comment_regex.'|'.$url_regex.'|'.$calc_regex.'/si', $string, $matches);