Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7052377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:22:33+00:00 2026-05-28T03:22:33+00:00

I need to get content of executable comments in mysqldump results, but for regexp

  • 0

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”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:22:34+00:00Added an answer on May 28, 2026 at 3:22 am

    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:

    %(               # opening RE delimiter, group start
      /\*            # comment open marker
        (  [^/*]     # non comment-marker characters
         | /(?!\*)   # '/' not followed by '*', so not a comment open
         | \*(?!/)   # '*' not followed by '/', so not a comment close
         | (?R)      # recursive case
        )*           # repeat any number of times
      \*/            # comment close marker
    )%x              # group end, closing RE delimiter, PCRE_EXTENDED
    

    In short:

    %(/\*([^/*]|/(?!\*)|\*(?!/)|(?R))*\*/)%x
    

    In use:

    <?php
    
    $commentRE = '%(/\*([^/*]|/(?!\*)|\*(?!/)|(?1))*\*/)%';
    $doc = <<<EOS
    
    USE database;
    
    /* comment
    and a
    /* nested comment /* me too */
       now exiting
     */
    the comment */
    
    
    /*!50003 text
    some text else
    /*
    comment
    also comment
    */
    text...
    and also text...
    */
    
    CREATE TABLE IF NOT EXISTS ...
    
    EOS;
    
    preg_match_all($commentRE, $doc, $parts);
    var_export($parts[0]);
    

    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...
    */',
    )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the Portuguese text content out of an Excel file and
This is the code on the script, i need to get the content from
I need to get content for this XPath: /html/body/div/table[2]/tbody/tr/td[2] It's copied from FireBug. How
hi i need to get specific content from the file get content but the
I need to get the content of URL bar (of currently opened tab) of
I need to get the complete content of a column of two tables in
I need a method to get the data from an external editor. def _get_content():
How can I get content of a DIV using regular expression. What I need
I need to get the last string content of the url between / and
I have one variable whose content I need to get from a remote server,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.