#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    How to replace multiline comments by empty lines?


    Hi,

    It's about replacing multiline comments in PL/SQL by empty lines with keeping the newlines in place.

    Though I'm quite familiar with regular expressions and
    have tried a lot of approaches, I haven't succeeded so far

    Let's assume we had a file like:
    --------- PL/SQL source -------------
    code line 1
    code lin 2
    /* begin of comment (line 3)
    comment line 4
    comment line 5
    end of comment (line 6) */
    code line 7
    /* begin and end of comment (line 8) */
    code line 9
    --------------------------------------

    I'd like to transform it into:
    --------- PL/SQL target -------------
    code line 1
    code lin 2
    /*


    */
    code line 7
    /**/
    code line 9
    --------------------------------------

    As you can see all comment text has vanished except for the new lines.

    Background:
    I need to keep the origin line numbers for further processing the code and referencing to the correct line numbers.

    Question:
    I'd like to get the job doe by means of regular expressions. The program behind is PERL, so that loops like while can easily implemented. However I'd prefer one regexp only.

    Any help is highly appreciated.


    Regards,
    uc007
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Short of a loop that keeps trying to replace stuff until it doesn't make any more replacements, which I hate, you need one regex evaluated during another: match each multi-line comment and replace it with (match each line and replace it with an empty line, ignoring the /* */).

    But I don't know enough Perl on how you'd do that best...

IMN logo majestic logo threadwatch logo seochat tools logo