вернуть только строки, не содержащие определенного слова - PullRequest
0 голосов
/ 04 марта 2020

У меня есть этот фрагмент текста

2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/Documents/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)    Downloading page WebParts...
2/27/2020 7:00:44 PM  138 (6036)     Downloading page web parts completed. 1 web parts successfully downloaded.
2/27/2020 7:00:44 PM  138 (6036)     Downloading page content...
2/27/2020 7:00:44 PM  138 (6036)       Restarting from position 8312...
2/27/2020 7:00:44 PM  138 (6036) Error:  error
double double
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/sdadasda/Forms/All.aspx...
2/27/2020 7:00:44 PM  138 (6036) Error: Unspecified error
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/21312332131/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/Documeents/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/wr/Forms/All.aspx...

Мне нужно вернуть все строки с:

  • «Страница просмотра загрузки:» часть из них
  • в них нет слова "Documents".

Ожидаемый результат:

2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/21312332131/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/Documeents/Forms/All.aspx...
2/27/2020 7:00:43 PM  138 (6036)   Downloading view page: /personal/test/wr/Forms/All.aspx...

Я пробовал использовать отрицательный прогноз и обычные [^ Docuemnts]. Ни один, кажется, не работает.

(\(\d+\)).*Downloading view page:\s\/personal\/\S+\/[^(Documents)]\/F
(\(\d+\)).*Downloading view page:\s\/personal\/\S+\/(?!Documents)\/F

1 Ответ

1 голос
/ 04 марта 2020

Одним из простых решений было бы просто использовать один отрицательный прогноз для исключения Documents:

^(?!.*\bDocuments\b).*\bDownloading view page:(?!\S).*$

Демо

Здесь полное объяснение шаблона регулярного выражения:

^                           from the start of the string
(?!.*\bDocuments\b)         assert that "Documents" does not occur anywhere in the line
.*\bDownloading view page:  then match "Downloading view page:"
(?!\S)                      assert that what follows is either whitespace or end of string
.*                          match the rest of the line
$                           until the end of the string
...