简体   繁体   English

正则表达式与多行字符串

[英]Regex with multiline string

I'm trying to make regex for getting diff for each file from project path diff file. 我正在尝试使正则表达式从项目路径差异文件获取每个文件的差异。 Here it is: 这里是:

--- 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

How to create regex pattern to match each file's diff? 如何创建正则表达式模式以匹配每个文件的差异? For example to match: 例如匹配:

Diff 1: 差异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

Diff 2: 差异2:

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

If possible at all, can you generate the diffs separately? 如果可能的话,您可以分别生成差异吗? If you have access to the repository this should be the simplest solution. 如果您有权访问存储库,则这应该是最简单的解决方案。

Otherwise, you cannot do it via regex - any line can start with --- or +++ . 否则,您将无法通过正则表达式进行操作-任何行都可以以---+++开头。 The correct solution for splitting the changes is to actually parse the diff format and skip the indicated number of + , - lines and possible other indicators for each file chunk. 拆分更改的正确解决方案是实际解析diff格式,并跳过每个文件块的指示数量的+-行和可能的其他指示符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM