Community
    • Login

    Bookmarking multi-line regex is not working as expected

    Scheduled Pinned Locked Moved General Discussion
    regex
    5 Posts 3 Posters 846 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Christian SchmittC
      Christian Schmitt
      last edited by

      Hi!

      I’m trying to filter a Postgresql log file for INSERT, UPDATE and DELETE statements, following this excellent tip here.

      My problem is that some of those statements have indented lines below them (see sample lines below) that i need to also match and bookmark so that those multi-line statements do not get cut off. I achieve the marking part with the following regex (the “. finds \r and \n” option is turned off):

      ^2019.?(?:“INSERT”|“UPDATE”|“DELETE”).?(:?((\R +|\t+).?))$

      The multi-line blocks do get selected correctly, but only the non-indented (“first”) lines of those blocks get bookmarked, even though the whole blocks are marked red by notepad++. Using the “Find” tab and searching forward, I made sure that all blocks do in fact get selected as a whole, but when I switch to “2 find buttons” and move backwards, the selection doesn’t move from block to block but goes through each “sub-line” separately. This behavior made me wonder if maybe the groups where the problem, that’s why I made them non-capturing, but that didn’t help.

      Any tips on how I would have to improve my regex would be greatly appreciated!

      Kind regards,

      Christian

      SAMPLE (except for the last line, every line/block gets matched):

      2019-05-15 16:09:28.125 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,36,“SELECT”,2019-05-15 16:09:28 UTC,3/1165,0,LOG,00000,“execute <unnamed>: SELECT ‘x’ FROM mdl_quiz_attempts WHERE userid = $1 AND quiz = $2 LIMIT 1”,“parameters: $1 = ‘2’, $2 = ‘1’”,“”
      2019-05-15 16:09:28.427 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,31,“DELETE”,2019-05-15 16:09:28 UTC,3/1160,0,LOG,00000,“execute <unnamed>: DELETE FROM mdl_question_attempt_step_data WHERE attemptstepid IN (
      SELECT qas.id
      FROM mdl_question_attempts qa
      JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id
      WHERE qa.questionusageid = $1)”,“parameters: $1 = ‘191’”,“”
      2019-05-15 16:09:28.429 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,32,“DELETE”,2019-05-15 16:09:28 UTC,3/1161,0,LOG,00000,“execute <unnamed>: DELETE FROM mdl_question_attempt_steps WHERE questionattemptid IN (
      SELECT qa.id
      FROM mdl_question_attempts qa
      WHERE qa.questionusageid = $1)”,“parameters: $1 = ‘191’”,“”
      2019-05-15 16:09:28.431 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,33,“DELETE”,2019-05-15 16:09:28 UTC,3/1162,0,LOG,00000,“execute <unnamed>: DELETE FROM mdl_question_attempts WHERE mdl_question_attempts.questionusageid = $1”,“parameters: $1 = ‘191’”,“”
      2019-05-15 16:09:28.432 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,34,“DELETE”,2019-05-15 16:09:28 UTC,3/1163,0,LOG,00000,“execute <unnamed>: DELETE FROM mdl_question_usages WHERE mdl_question_usages.id = $1”,“parameters: $1 = ‘191’”,“”
      2019-05-15 16:09:28.433 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,35,“DELETE”,2019-05-15 16:09:28 UTC,3/1164,0,LOG,00000,“execute <unnamed>: DELETE FROM mdl_quiz_attempts WHERE id = $1”,“parameters: $1 = ‘32’”,“”
      2019-05-15 16:09:28.435 UTC,“moodle”,“sb_moodle”,27233,“::1:43344”,5cdc39b8.6a61,36,“SELECT”,2019-05-15 16:09:28 UTC,3/1165,0,LOG,00000,“execute <unnamed>: SELECT ‘x’ FROM mdl_quiz_attempts WHERE userid = $1 AND quiz = $2 LIMIT 1”,“parameters: $1 = ‘2’, $2 = ‘2’”,“”

      Alan KilbornA 2 Replies Last reply Reply Quote 2
      • Alan KilbornA
        Alan Kilborn @Christian Schmitt
        last edited by

        @Christian-Schmitt

        The multi-line blocks do get selected correctly, but only the non-indented (“first”) lines of those blocks get bookmarked

        This has come up before. Unfortunately, what you’ve described is how it is known to work. :(

        1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Christian Schmitt
          last edited by

          @Christian-Schmitt

          There’s a Pythonscript in this thread --don’t be put off by that thread’s title–that provides a workaround if you’d consider using that plugin to help solve your problem.

          1 Reply Last reply Reply Quote 1
          • Christian SchmittC
            Christian Schmitt
            last edited by

            Hi Alan,

            thanks for the quick reply and pointing me to the thread, I’ll try it out!

            Just for completeness (in case someone is interested in the regex), here’s the correct syntax and sample lines on Pastebin.

            Best regards,

            Christian

            1 Reply Last reply Reply Quote 2
            • guy038G
              guy038
              last edited by guy038

              Hello, @christian-schmitt,

              Just try this regex, below. It should bookmark all the lines that you want to !

              (?-is)^2019.*"(INSERT|UPDATE|DELETE)".*|^\h+.+

              How this regex works :

              • First, the in-line modifiers (?-is) assure that :

                • The regex engine will consider any dot as a single standard character, only ( -s part )

                • The search is performed in an non-insensitive to case way ( -i part )

              • Then, the regex is composed of two alternatives, delimited with the | alternation symbol

                • The part ^2019.*"(INSERT|UPDATE|DELETE)".*, similar to your version, search for 2019, at beginning of line, followed wiht any range, even null, of standard characters, till one of the 3 words INSERT, UPDATE or DELETE, surrounded by double-quotes, and then, followed with the remainder of current line

                • The part ^\h+.+ searches for any line beginning with either some space or tabulation character(s) ( so horizontal blank chars ) and the non-null remainder of these lines

              Note that if you just want to bookmark the lines, ignoring the red highlighting, you just need the shortened version, below :

              (?-is)^2019.*"(INSERT|UPDATE|DELETE)"|^\h+

              Disable the View > Word wrap option for a better lisibility ;-))

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors