Hi Bruno, Bruno Haible <br...@clisp.org> writes:
> Thanks for this recipe. I think this is worth a unit test, since it > is a special case that is otherwise not tested. Agreed. I can add one later today. > The regular expression doesn't seem right: [...] > The point of using a non-greedy operator is to not include newlines > in the match, right? So, > re.compile(r'^ACLOCAL_AMFLAGS[\t ]*=[\t ]*([^#]*)', re.MULTILINE) > wouldn't work? Oops, good catch. I was trying to be clever and failed. :) Here is something like what I was trying to do: =================== import re string = """ ACLOCAL_AMFLAGS = ACLOCAL_AMFLAGS = -I m4 -I glm4 # ignore this please """ pattern = re.compile(r'^ACLOCAL_AMFLAGS[\t ]*=[\t ]*(.+?)[\t ]*(?:#|$)', re.MULTILINE) print('"' + re.search(pattern, string).group(1) + '"') =================== Not sure if Makefile.am's are written like that in practice but here is the output: $ ./main.py "-I m4 -I glm4" Collin