Strip block comments: Difference between revisions

Added PHP solution
(Added Julia language)
(Added PHP solution)
Line 1,522:
function something() {
}
</pre>
 
=={{header|PHP}}==
<lang PHP>
function strip_block_comments( $test_string ) {
$pattern = "/^.*?(\K\/\*.*?\*\/)|^.*?(\K\/\*.*?^.*\*\/)$/mXsus";
return preg_replace( $pattern, '', $test_string );
}
 
echo "Result: '" . strip_block_comments( "
/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
 
/**
* Another comment.
*/
function something() {
}
" ) . "'";
</lang>
 
{{out}}
<pre>
Result: '
 
function subroutine() {
a = b + c ;
}
 
 
 
function something() {
}
'
</pre>
 
Anonymous user