0

I am trying to find all text blocks in a file, that contain a string, matching the following regex: D[:\/\\]+Apps[\/\\]+ and are surrounded by double newlines.

For example in this text:

00,36,00,31,00,39,00,33,00,34,00,65,00,30,00,38,00,39,00,00,00,00,00,00,00,\
  00,00,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGenService\Roots\D:/Apps/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/Architecture Tools/GraphProviderPackage/Microsoft.VisualStudio.GraphProviderPackage.dll]
"Status"=dword:00000003

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGenService\Roots\D:/Programs/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/Architecture Tools/GraphProviderPackage/Microsoft.VisualStudio.GraphProviderPackage.dll\0]
"Scenario"=dword:00000020

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2....

What I want to be found is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\NGenService\Roots\D:/Apps/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/Architecture Tools/GraphProviderPackage/Microsoft.VisualStudio.GraphProviderPackage.dll]
"Status"=dword:00000003

Having in mind, that "Status"=dword:00000003 is on a different line

So far this is the closest I got:

\r?\n\r?\n(([\s\S](?!\r?\n\r?\n))*)D[:\/\\]*Apps[\/\\]*(([\s\S](?!\r?\n\r?\n))*).\r?\n\r?\n

but Notepad++ says that my regex is invalid, even though in regex101 it matches it the way I want it.

  • First, you should probably have something like **D[:\/]*** - because after **D** you have 2 characters, not one. I change d the order of the slashes only because the SE script does some voodoo :) No need to change in original. It is probably the same with **(\s\S)*** – virolino Mar 16 '23 at 14:14
  • Also, please save the Regex101 search and provide us the link, so we can understand your situation better. – virolino Mar 16 '23 at 14:17
  • Are these single or multiple lines? Do they always start with the same string? – The fourth bird Mar 16 '23 at 15:26
  • The text could be comprised of multiple lines and should be matched if it doesn't contain consecutive newline characters. – Veselin_01 Mar 17 '23 at 10:32

1 Answers1

1
  • Ctrl+F
  • Find what: \R\R\K\[.+?D:/Apps/.+?(?=\R\R)
  • TICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • TICK . matches newline
  • Replace all

Explanation:

\R\R            # 2 any kind of linebreak
\K              # forget them
\[              # openning square bracket
.+?             # 1 or more any character, not greedy
D:/Apps/        # literally
.+?             # 1 or more any character, not greedy
(?=\R\R)        # poritive lookahead, make sure we have 2 linebreak after

Screenshot:

enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
  • Thank you for the answer, but the string "Status"=dword:00000003 is on a new line and it should still be matched. Using this method - it wouldn't. – Veselin_01 Mar 17 '23 at 10:34
  • I also edited my question, to clarify what should be matched, please check it out again. – Veselin_01 Mar 17 '23 at 14:14
  • @Veselin_01: Sorry but I don't see any problem! It works, doesn't it? – Toto Mar 17 '23 at 14:57
  • Well it matches a string with the 2 paragraphs together, when it should only select the one with "D:\Apps" in it. – Veselin_01 Mar 17 '23 at 16:54
  • @Veselin_01: As you can see in screenshot, it works fine. If you have another test case than the one you've given please dit your question and add this test case. – Toto Mar 17 '23 at 17:08
  • It is edited now, please check it out. – Veselin_01 Mar 20 '23 at 06:33
  • I have provided some more information, could you check it out? – Veselin_01 Mar 23 '23 at 13:00
  • @Veselin_01: I don't see any modifications in your question since March 17. My solution works fine with your actual example. – Toto Mar 24 '23 at 09:12
  • There is a modification. One paragraph is added which breaks your solution as you can see in the following screenshot: https://imgur.com/a/bsGxa8D – Veselin_01 Mar 26 '23 at 09:42
  • @Veselin_01:Just change `+` into `.+?` (not greedy). See my edit. – Toto Mar 26 '23 at 09:49