fork download
  1. <?php
  2.  
  3. $strs = ['Connection variable = new DBConnection', 'variable = new DBConnection', '//Connection variable = new DBConnection', '//variable = new DBConnection'];
  4. $rx = '~^(\s*//)?(?:\s*Connection\s+)?(.+?)\s*=\s*new\s+DBConnection~';
  5. foreach ($strs as $s) {
  6. echo "$s:\n";
  7. if (preg_match($rx, $s, $m)) {
  8. if (empty($m[1])) {
  9. echo "FOUND:" . $m[0] . "\n--------------\n";
  10. }
  11. } else {
  12. echo "NOT FOUND\n--------------\n";
  13. }
  14. }
Success #stdin #stdout 0.02s 23636KB
stdin
Standard input is empty
stdout
Connection variable = new DBConnection:
FOUND:Connection variable = new DBConnection
--------------
variable = new DBConnection:
FOUND:variable = new DBConnection
--------------
//Connection variable = new DBConnection:
//variable = new DBConnection: