Community
    • Login

    Notepad++ RegEx question

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 572 Views 2 Watching
    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.
    • Smudge the catS Offline
      Smudge the cat
      last edited by

      Hi, everyone. How can I search for 2 matches but it shows only if the other one matches as well? For example: I have a very long text file with over 100000 lines currently and they all have dates. I want to search for the names “Soradesuu|SetoKaiba|Karumi|Ahmetgojo1905|Marfrey2|Darksy|Kenzushiyato|Krombex|Atarikafa|Castial06|Jawaxdd|Aroxwex|Niwsuax|Sauron80|Kazim_donmez” but only see their messages sent by them in 2025-02-12. How can I do this?

      mkupperM 1 Reply Last reply Reply Quote 0
      • mkupperM Offline
        mkupper @Smudge the cat
        last edited by mkupper

        @Smudge-the-cat, you have the right idea about using Soradesuu|SetoKaiba|Karumi|Ahmetgojo1905|Marfrey2|Darksy|Kenzushiyato|Krombex|Atarikafa|Castial06|Jawaxdd|Aroxwex|Niwsuax|Sauron80|Kazim_donmez and so using that I will show a couple of things.

        Let’s say you have one line per record and the date is before the user name list. This RegEx matches a date followed by any number of characters we don’t care about followed by a list of user names. You can do
        2025-02-12.*(Soradesuu|SetoKaiba|Karumi|Ahmetgojo1905|Marfrey2|Darksy|Kenzushiyato|Krombex|Atarikafa|Castial06|Jawaxdd|Aroxwex|Niwsuax|Sauron80|Kazim_donmez)

        I wrapped the user name list in (parentheses) so that the RegEx system knows that the list of user names is a sub-expression. Without the parentheses it would be doing a match for 2025-02-12.*Soradesuu or one of the other user names but without the date in front of it.

        If it’s one line per record and the date is after the name then use
        (Soradesuu|SetoKaiba|Karumi|Ahmetgojo1905|Marfrey2|Darksy|Kenzushiyato|Krombex|Atarikafa|Castial06|Jawaxdd|Aroxwex|Niwsuax|Sauron80|Kazim_donmez).*2025-02-12

        If the thing is split over two or more lines then you can use
        ^Date: 2025-02-12\R(.*\R){0,3}User: (Soradesuu|SetoKaiba|Karumi|Ahmetgojo1905|Marfrey2|Darksy|Kenzushiyato|Krombex|Atarikafa|Castial06|Jawaxdd|Aroxwex|Niwsuax|Sauron80|Kazim_donmez)

        I added several things.

        • \R matches the end of a line.
        • (.*\R){0,3} matches zero to three lines where we don’t care about the content.
        • ^Date: with the ^ matches the word Date: at the start of a line. I don’t need a ^ in front of User: as we are already at the start of a line.

        That will allow for matching record where the date line is 1 to 3 lines before the user line. The {0,3} restriction is to prevent a match where you have Date: 2025-02-12 in the file and a few million lines later is a User: line with one of the people you are interested in.

        Hopefully that’s enough to get you started with a RegEx that makes sense to you.

        Smudge the catS 1 Reply Last reply Reply Quote 2
        • Smudge the catS Offline
          Smudge the cat @mkupper
          last edited by

          @mkupper The first one you’ve wrote worked wonderfully, thank you for your response and the help, I really appreciate it! Have a nice day ദ്ദി( • ᴗ - ) ✧

          1 Reply Last reply Reply Quote 0
          • guy038G Offline
            guy038
            last edited by guy038

            Hello, @smudge-the-cat, @mkupper and All,

            @mkupper, if we’re certain that each record contains, both, the 2025-02-12 date and a name, an other solution could be :

            FIND / MARK (?-is)(?=.*2025-02-12)(?=.*(Soradesuu|Setokaiba|.......|Sauron80|Karim_Dommez)).+


            In other words, it would match, from beginning of line, all the line contents ONLY IF, BOTH :

            • It contains the 2025-02-12 date

            • It contains a name of the list, with the same case, between parentheses which can be re-used as ${1}, if necessary

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors