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.

4
  • 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)* Commented Mar 16, 2023 at 14:14
  • Also, please save the Regex101 search and provide us the link, so we can understand your situation better. Commented Mar 16, 2023 at 14:17
  • Are these single or multiple lines? Do they always start with the same string? Commented Mar 16, 2023 at 15:26
  • The text could be comprised of multiple lines and should be matched if it doesn't contain consecutive newline characters. Commented Mar 17, 2023 at 10:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

10 Comments

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.
I also edited my question, to clarify what should be matched, please check it out again.
@Veselin_01: Sorry but I don't see any problem! It works, doesn't it?
Well it matches a string with the 2 paragraphs together, when it should only select the one with "D:\Apps" in it.
@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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.