fork download
  1. <?php
  2.  
  3. $re = '~^(\s*//.*)(*SKIP)(*F)|^(?:\s*Connection\s+)?(.+?)\s*=\s*new\s+DBConnection~m';
  4. $str = "Connection variable = new DBConnection\n variable = new DBConnection\n //\n //Connection variable = new DBConnection\n //variable = new DBConnection\n // Connection variable = new DBConnection\n // variable = new DBConnection";
  5. if (preg_match_all($re, $str, $matches)) {
  6. print_r($matches[0]);
  7. }
  8.  
Success #stdin #stdout 0.02s 23756KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Connection variable = new DBConnection
    [1] =>     variable = new DBConnection
)