Notepad++ RegEx question
-
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?
-
@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_donmezand 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 for2025-02-12.*Soradesuuor 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-12If 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.
\Rmatches 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 wordDate:at the start of a line. I don’t need a^in front ofUser: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 haveDate: 2025-02-12in the file and a few million lines later is aUser: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.
-
@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 ദ്ദി( • ᴗ - ) ✧
-
Hello, @smudge-the-cat, @mkupper and All,
@mkupper, if we’re certain that each record contains, both, the
2025-02-12date 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-12date -
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
-