我希望在文档中找到与模式列表不匹配的所有非空行。例如,在下面的文档片段中,我想要一个与行号2、4、5、6、18、19、20和21相匹配的正则表达式。
我想排除类似8,10,12,14,16和所有空行的行。
逆模式是(?i)^.*02 December_|^\s*Python Proprietary|^\s*Python Regular Expression Specification|^.*page\s+\d+|^\s*$。我想要一个与上述模式不匹配的所有行匹配的模式。
1:
2:This module provides regular expression matching operations.
3:
4:Regular expressions use the backslash character ('\') to indicate special forms
5:or to allow special characters to be used without invoking their special
6:meaning.
7:
8:Python Regular Expression 02 December 1999
9:
10: Python Proprietary
11:
12:----------------------- Page 292-----------------------
13:
14:PYTHON RE SPECIFICATION Version 2.7 [Vol 9, Part Q] page 983
15:
16:Python Regular Expression Specification
17:
18:It is important to note that most regular expression operations are available as
19:module-level functions and RegexObject methods. The functions are shortcuts that
20:don’t require you to compile a regex object first, but miss some fine-tuning
21:parameters.
22:P.S. -
发布于 2016-03-14 09:21:43
你可以用消极的眼光看未来:
REGEX
^(?i)(?!-+\s+Page\s+\d+-+|Python\s+Regular\s+Expression\s+\d{2}.+\d{4}|.+Python\s+Proprietary|PYTHON\s+RE SPECIFICATION\s+Version.+\s+page\s+\d+|Python\s+Regular\s+Expression\s+Specification).+$演示
描述

发布于 2016-03-14 08:22:39
尝尝这个
^.*?Python Regular Expression.*?$(*SKIP)(*FAIL)|^.*?Python Proprietary.*?$(*SKIP)(*FAIL)|.*?Page \d+.*?$(*SKIP)(*FAIL)|^$(*SKIP)(*FAIL)|^.*?$结果:
匹配8行2、4、5、6、18、19、20和21行。
解释:
^.*?Python Regular Expression.*?$(*SKIP)(*FAIL)不包括第6、第16行。
^.*?Python Proprietary.*?$(*SKIP)(*FAIL)不包括第10行。
.*?Page \d+.*?$(*SKIP)(*FAIL)不包括第12、14行。
^$(*SKIP)(*FAIL)排除所有空行。
^.*?$匹配所有其他行。
https://stackoverflow.com/questions/35982458
复制相似问题