Community
    • Login

    RegEx - Finding strings when another substring not present

    Scheduled Pinned Locked Moved General Discussion
    14 Posts 3 Posters 755 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.
    • Alan KilbornA
      Alan Kilborn @Zeff Wheelock 0
      last edited by Alan Kilborn

      @Zeff-Wheelock-0 said in RegEx - Finding strings when another substring not present:

      extract the email addresses on all lines that had OutboundConnectionCommand

      This is different in a big way from your original request.
      Evolving needs tends to confuse those offering help…
      But it appears you are well on your way to solving your own problem, so that’s great!

      Zeff Wheelock 0Z 1 Reply Last reply Reply Quote 1
      • Zeff Wheelock 0Z
        Zeff Wheelock 0 @Alan Kilborn
        last edited by

        @Alan-Kilborn
        I apologize for that. After seeing your answer, I realized that I probably needed to add more context than the original ask.

        I have tried:

        (?=.*\bOutboundConnectionCommand\b)(?=.*FROM)(?<=\<).*(?=\>)
        

        But it seems to select the entire line. Am I close?

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Zeff Wheelock 0
          last edited by

          @Zeff-Wheelock-0

          I’ve sort of lost track of what the full need is, but I think you can match the entire line with the email address into capture group 1 with:

          Find: (?-is)^.*?OutboundConnectionCommand.*?FROM:<(.+?)>.*

          Then you might replace with ${1} ?

          Again, a lot of info, so I can’t really pick off what is needed.

          Zeff Wheelock 0Z 1 Reply Last reply Reply Quote 1
          • Zeff Wheelock 0Z
            Zeff Wheelock 0 @Alan Kilborn
            last edited by

            @Alan-Kilborn
            Unfortunately, that just blanked out the whole line. I am trying to match any line that contains the bolded content and get the email address within the Less Than/Greater Than delimiters:

            2023-03-07 01:30:24 1.2.3.4 OutboundConnectionCommand SMTPSVC1 SERVER01- 0 MAIL - FROM:<return_email_address_between_delimiters@abc.xyz>+SIZE=933660 0 0 4 0 141 SMTP - - - -

            Thanks for helping me out!

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Zeff Wheelock 0
              last edited by Alan Kilborn

              @Zeff-Wheelock-0 said in RegEx - Finding strings when another substring not present:

              that just blanked out the whole line

              Hmm, my testing shows that it replaces the line with ONLY the email address.

              get the email address

              But we don’t know what this means.
              Maybe your goal isn’t replacement in the original file…

              If you literally mean you just want a copy of the email addresses that match the criteria you’ve previously outlined, I’d suggest a Mark operation followed by a Copy Marked Text operation followed by a paste (somewhere else).

              c65cc211-7bf4-49f0-8e3f-e66c8dbc85b7-image.png

              Find: (?-is)^.*?OutboundConnectionCommand.*?FROM:<\K.+?(?=>)

              Press Mark All.
              Press Copy Marked Text.
              Move to new tab; paste:

              5753d674-bf64-416c-af22-df29e6e6847e-image.png

              Zeff Wheelock 0Z Mark OlsonM 2 Replies Last reply Reply Quote 4
              • Zeff Wheelock 0Z
                Zeff Wheelock 0 @Alan Kilborn
                last edited by

                @Alan-Kilborn
                Thanks! I had the previous version of Notepad++. Upgraded to the new version and your solution worked flawlessly and fast! Thanks for the help!

                Alan KilbornA 1 Reply Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @Zeff Wheelock 0
                  last edited by

                  @Zeff-Wheelock-0 said in RegEx - Finding strings when another substring not present:

                  I had the previous version of Notepad++. Upgraded to the new version

                  I don’t think an upgrade had anything to do with it, but it is good that you have some satisfaction!

                  Zeff Wheelock 0Z 1 Reply Last reply Reply Quote 1
                  • Mark OlsonM
                    Mark Olson @Alan Kilborn
                    last edited by

                    The \K operator for forgetting all the text found so far is really cool and I’m glad I learned about it.

                    Alan KilbornA 1 Reply Last reply Reply Quote 1
                    • Alan KilbornA
                      Alan Kilborn @Mark Olson
                      last edited by

                      @Mark-Olson said in RegEx - Finding strings when another substring not present:

                      The \K operator for forgetting all the text found so far is really cool and I’m glad I learned about it.

                      Not strictly necessary for the above, though.
                      If this wasn’t an “evolved” solution I probably wouldn’t have used it.
                      But it was a matter of “where are we now”…ok…CANCEL with \K!

                      1 Reply Last reply Reply Quote 0
                      • Zeff Wheelock 0Z
                        Zeff Wheelock 0 @Alan Kilborn
                        last edited by

                        @Alan-Kilborn just adding that the version that I was using did not have the option in Mark to Copy Marked Text. I was one version behind. Upgrading Notepad++ gave me that option.

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