fork download
  1. <?php
  2.  
  3. $str = 'Hello world //this is a comment
  4. Testing //not testing
  5. Test again';
  6.  
  7. echo preg_replace('~//.*$~m', 'foo \\0 bar', $str);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Hello world foo //this is a comment bar
Testing foo //not testing bar
Test again