$re = '/^\s*\/\*.*?\*\//ms';
$str = '/**
* base comment
* (c) SOMEBODY SOMETIME
* something
*/
///<!-- ------metadata-XML------- -->
/// <module type="javascript"> A
///<desc> some desc
/// </desc>
(function( a /* param A */) { // programmers comment ... enclosure
/*! user doc
this module ....
* reguired
.....
*/
var b={}; // programmers in line comment
// single line comments
// The cookie spec says up to 4k per cookie, so at ~50 bytes per entry
// that gives a maximum of around 80 items as a max value for this field
b.a=a;
var str = " tttt //this is not comment ! tttt "
var str2 = " tttt /* this is not comment too ! \\
.............. */ ttt ";
global.b = b;
}(global);
///</module>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php