fork download
  1. <?php
  2.  
  3. // your code goes here
  4. $css = ":root{\n --bodyBackgroundColor: #ffffff; /*teste teste teste*/\n --bodyTextColor: #ffffff; // outro\n --buttonBorderFocus: #1d2124; // testando\n}";
  5.  
  6. // o * precisa ser escapado (\*)
  7. preg_match_all('{\s*\\--([A-Za-z1-9_\-]+)(\s*:\s*(.*?);)?\s*(?|//\s*(.*)|/\*(.*)\*/)?}', $css, $resultado);
  8. var_dump($resultado);
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
array(5) {
  [0]=>
  array(3) {
    [0]=>
    string(58) "
    --bodyBackgroundColor: #ffffff; /*teste teste teste*/"
    [1]=>
    string(39) "
    --bodyTextColor: #ffffff; // outro"
    [2]=>
    string(46) "
    --buttonBorderFocus: #1d2124; // testando"
  }
  [1]=>
  array(3) {
    [0]=>
    string(19) "bodyBackgroundColor"
    [1]=>
    string(13) "bodyTextColor"
    [2]=>
    string(17) "buttonBorderFocus"
  }
  [2]=>
  array(3) {
    [0]=>
    string(10) ": #ffffff;"
    [1]=>
    string(10) ": #ffffff;"
    [2]=>
    string(10) ": #1d2124;"
  }
  [3]=>
  array(3) {
    [0]=>
    string(7) "#ffffff"
    [1]=>
    string(7) "#ffffff"
    [2]=>
    string(7) "#1d2124"
  }
  [4]=>
  array(3) {
    [0]=>
    string(17) "teste teste teste"
    [1]=>
    string(5) "outro"
    [2]=>
    string(8) "testando"
  }
}