多行字符串的正则表达式

2024-04-25 19:47:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使regex从项目路径diff文件中获取每个文件的diff。在这里:

--- Training/main/1/a   (revision 18 06 2013 06:48)
+++ Training/main/1/a   (revision 18 06 2013 06:48)
@@ -1,1 +0,0 @@
-isdfsdfsdsadasdasd
\ No newline at end of file
--- Training/main/1/abc (revision After)
+++ Training/main/1/abc (revision After)
@@ -0,0 +1,1 @@
+isdfsdfsdsadasdasd
\ No newline at end of file
--- Training/main/1/test.txt    (revision 18 06 2013 06:48)
+++ Training/main/1/test.txt    (revision After)
@@ -1,1 +1,3 @@
-sfaa
\ No newline at end of file
+sfaaasdasssssdsadasdas
+
+test with moving files on depot
\ No newline at end of file

如何创建正则表达式模式来匹配每个文件的差异?例如匹配:

差异1:

--- Training/main/1/a   (revision 18 06 2013 06:48)
+++ Training/main/1/a   (revision 18 06 2013 06:48)
@@ -1,1 +0,0 @@
-isdfsdfsdsadasdasd
\ No newline at end of file

差异2:

--- Training/main/1/abc (revision After)
+++ Training/main/1/abc (revision After)
@@ -0,0 +1,1 @@
+isdfsdfsdsadasdasd
\ No newline at end of file

Tags: 文件ofnotestmaintrainingnewline差异
1条回答
网友
1楼 · 发布于 2024-04-25 19:47:28

如果可能的话,你能单独生成差异吗?如果您可以访问存储库,这应该是最简单的解决方案。你知道吗

否则,您不能通过regex来完成这项工作—任何行都可以以 -+++开头。分割更改的正确解决方案是实际解析diff格式,并跳过指定的+-行数和每个文件块可能的其他指示符。你知道吗

相关问题 更多 >