Community
    • Login

    Notepad++ RegEx question

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 151 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.
    • Smudge the catS
      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
        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
          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
            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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors