-1

The results of diff will give you :

    @@ -74,6 +73,7 @@ 
    <dependency> <groupId>com.jolbox</groupId> 
    <artifactId>bonecp-test
    - commons</artifactId> 
    + <classifier>${project.classifier}</classifier>     
    <scope>test</scope>

I want to way to get only these numbers from the headers 74,6 and 73,7 ; any idea how can I achieve that? I am using python code

waled
  • 3
  • 2
  • Have you tried regex? – Daniil Fajnberg Sep 27 '22 at 06:47
  • well , I do not have experience at all in regex – waled Sep 27 '22 at 06:48
  • you don't even need regexps: print lines that start with "@@" – LeGEC Sep 27 '22 at 07:29
  • what did you try? Where is your code? This line starts with `@@` so you can get line-by-line and check `line.startswith("@@")`, and later you can `data = line.split(" ")` to create list with `["@@", "-74,6", "+73,7", "@@"]` and get `data[1]` `data[2]` – furas Sep 27 '22 at 07:50
  • What is the the goal behind this? Also: Are the amount of context lines relevant to you? Would having no context lines (`-U0`) be an option? I'm asking this because the number of context lines will affect what numbers are in the `@@` lines. So yeah... that's why I wonder what you need this for. (And your fake/invalid diff hunk example isn't helping :D) – Jay Sep 27 '22 at 10:55

1 Answers1

0

You could use regex to extract what you want

([-\+]?\d+,[-\+]?\d+)

https://regex101.com/r/1DPH5e/2

If you want to make it more specific in case your diff includes similar patterns:

@@\s([-\+]?\d+,[-\+]?\d+)\s([-\+]?\d+,[-\+]?\d+)

https://regex101.com/r/3G42Lz/2

You can then extract the groups from python. This answer has a good description of how to do that.

M B
  • 2,700
  • 2
  • 15
  • 20