Any idea how to extract all the files (1.css, 2.css, 3.css) from this string using regex? $string = '@import url("1.css"); @import url(2.css); @import "3.css"; @import url("4.css") all;'; PHP:
neah...does not work at all.. I got very close but still far away preg_match_all ( '/@import[^>]+\p{P}(.*?).css/si', $string, $sheet ); PHP:
hey nico...any idea why your regex fails to extract in this situation (a valid css import): $str = '@import: url(\'test.css\');'; function searchCSSImports ( $str ) { preg_match_all ( '/import[^>]+(?:url\()?["\']?([^"\'\)]+)/i', $str, $sheet ); return $sheet [ 1 ]; } echo '<pre>'; print_r ( searchCSSImports ( $str ) ); echo '</pre>'; PHP:
'/@import\s*:?\s*(?:url\()?["\']?([^"\'\)]+)/i' PHP: Works for me with these examples. (Didn't test others, if there are any) $str = ' @import: url(\'test.css\'); @import: \'test2.css\'; @import url("1.css"); @import url(2.css); @import "3.css"; @import url("4.css") all;'; PHP: