From: Sebastian Schuberth Date: Mon, 25 Apr 2016 07:35:48 GMT Subject: Re: [PATCH v3 3/3] git-p4: fix Git LFS pointer parsing Message-ID: In-Reply-To: <8340C6E5-C774-46EE-A1F9-1C4C7DF9CEB9@gmail.com> On Mon, Apr 25, 2016 at 9:33 AM, Lars Schneider wrote: >> if you're omitting lines from the output. Also, the regex matches >> against the whole multi-line string. That is, if the file for some >> reason was ending in '\n\n' instead of just '\n', the '.*' would match >> almost all content of the pointer file, not just the remains of the >> preamble. One way to fix this would be to use >> >> re.sub(r'Git LFS pointer for [^\n]+\n\n', '', pointerFile) >> >> instead. > > In general you are right as "*" is greedy. However, in Python "." matches any > character except a newline [1]. Therefore I think the regex is correct. Ah, thanks for pointing that out. Looks ok to me then. > Nevertheless... thanks for making me read the line again. I forgot to > assign the pointerFile variable in the version I sent around :-( > > This is how it should be: > > pointerFile = re.sub(r'Git LFS pointer for.*\n\n', '', pointerFile) Right. Good you've catched that! -- Sebastian Schuberth