我想知道是否可以为这种情况构建一个正则表达式。在某些上下文中,我正在使用 patch(diff) 文件来查找某些 ASCII 文件类型之间的差异,并且我想匹配此处所示的字符串部分。
注意:这些“ASCII 文件类型”中的注释是“!”之后的注释
示例 1.
- Content AAAA ! Comment which can be ignored
- Content BBBB ! Comment which can be ignored
- Content CCCC ! Comment which can be ignored
+ Content AAAA ! Comment which can be ignored even if it is different
+ Content BBBB ! Comment which can be ignored even if it is different
+ Content CCCC ! Comment which can be ignored even if it is different
示例 2.
- Exact same content ! Comment which can be ignored
+ Exact same content ! Comment which can be ignored even if it is different
因此,如果内容部分(+)和(-)相同的话,注释将被忽略。
这不应该匹配,因为其内容不同,
示例3.
- Content AAAA ! Comment which can be ignored
- Content BBBB ! Comment which can be ignored
- Content CCCC ! Comment which can be ignored
+ Content 1111 ! Comment which can be ignored even if it is different
+ Content 2222 ! Comment which can be ignored even if it is different
+ Content 3333 ! Comment which can be ignored even if it is different
对于单行差异(如示例 2 所示),我有一个有效的正则表达式,如下所示
-(.+)!.*\r?\n\+\1.+
但我无法为多行字符串创建一个字符串,如示例 1 所示。