Unclear about verbose regex syntax (excaping whitespace)

R

Roy Smith

The docs for re.VERBOSE say, "Whitespace within the pattern is ignored, except when [...] preceded by an unescaped backslash". It's unclear exactly what that means. If my pattern is:

<backslash><space><space>

is the second space considered to be preceded by a backslash, and thus taken literally, or does the backslash only apply to the first <space>? I suspect the latter, but it's somewhat ambiguous.
 
T

Tim Chase

The docs for re.VERBOSE say, "Whitespace within the pattern is
ignored, except when [...] preceded by an unescaped
backslash". It's unclear exactly what that means. If my
pattern is:

<backslash><space><space>

is the second space considered to be preceded by a backslash,
and thus taken literally, or does the backslash only apply to
the first<space>? I suspect the latter, but it's somewhat
ambiguous.

You're right (easily testable) in your suspicions that the second
space is ignored in this case. I suppose the documentation could
be tweaked to read "immediately preceded".

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top