I need to get content of executable comments in mysqldump results, but for regexp
/\/\*\!\d+\s+(.*?)\*\//s
and input data like this:
/*!50003 text
some text else
/*
comment
also comment
*/
text...
and also text...
*/
I get wrong result because it get data only from “text” to “also comment” lines. How can I to skip comment into comment?
Thanks.
UPD: I cannot use “^” and “$” to mark start and end of input, because I have a lot ot executable statements in input.
UPD2: Output I want:
text
some text else
/*
comment
also comment
*/
text...
and also text...
NOT all input how in comment below. It’s very strange, I think, get the same output as input.
UPD3:
Start of executable comment must be /*!ANYNUMBER. It must be skipped and not included in output. End of executable comment is simply */ Right output example is presented in “UPD2”.
Pure regular expressions can’t handle nesting, but PHP’s flavor can by using recursion. Using the PCRE_EXTENDED modifier so we can have whitespace and comments:
In short:
In use:
Result:
array ( 0 => '/* comment and a /* nested comment /* me too */ now exiting */ the comment */', 1 => '/*!50003 text some text else /* comment also comment */ text... and also text... */', )