RegEx - Finding strings when another substring not present
-
I have figured out how to find the line I want using:
(?=.*\bOutboundConnectionCommand\b)(?=.*FROM)
Now I just need to extract the email between the < and >
-
@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! -
@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?
-
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.
-
@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!
-
@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).
Find:
(?-is)^.*?OutboundConnectionCommand.*?FROM:<\K.+?(?=>)
Press Mark All.
Press Copy Marked Text.
Move to new tab; paste: -
@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! -
@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!
-
The
\K
operator for forgetting all the text found so far is really cool and I’m glad I learned about it. -
@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
! -
@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.