Python 3 regex?

Chris Angelico rosuav at gmail.com
Mon Jan 12 13:48:10 EST 2015


On Tue, Jan 13, 2015 at 5:03 AM, Jason Bailey <jbailey at emerytelcom.com> wrote:
> Unfortunately, I get no matches. From output on the command line, I can see
> that Python is adding extra backslashes to my re.compile string. I have
> added the raw 'r' in front of the strings to prevent it, but to no avail.
>

Regexes are notoriously hard to debug. Is there any particular reason
you _have_ to use one here? ISTM you could simplify it enormously by
just looking for the opening string:

shared_network = "My-Network-FECO"
network = filebody.split("\nshared-network "+shared_network+"
{",1)[1].split("\n}\n")[0]

Assuming your file is always correctly indented, and assuming you
don't have any other instances of that header string, you should be
fine.

ChrisA



More information about the Python-list mailing list