简体   繁体   中英

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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