On 08/04/2016 03:27 AM, Alan Gauld via Tutor wrote:
On 04/08/16 02:54, Jim Byrnes wrote:

Is the second example a special case?

phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)')

I ask because it produces the same results with or without the ' r '.

That's because in this specific case there are no conflicts between
the regex escape codes and the Python escape codes. In other
words Python does not treat '\(' or '\d' as special characters
so it doesn't change the string passed to the regex.
(It would be a different story if you had used, say, a
'\x' or '\n' or '\b' in the regex.)

In general you should proceed with caution and assume that
there might be a Python escape sequence lurking in the regex
and use raw just in case.


Ok, thanks again.  I understand what is going on now.

Regards,  Jim

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to