Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 5, raw strings #34

Open
caoimhinoc opened this issue Jan 20, 2015 · 1 comment
Open

Chapter 5, raw strings #34

caoimhinoc opened this issue Jan 20, 2015 · 1 comment

Comments

@caoimhinoc
Copy link

Hi Mark,

I'm enjoying your book on python 3, but I don't understand the part in chapter 5 where you talk about raw strings. It seems that by adding r in front of '\bROAD$' you should achieve the opposite of what you want to, which is to have \b interpreted as a word boundary. Instead you'd get a slash followed by a b. In other words, why would you want the \ to be escaped here?

Except of course that the code works. But I don't know why it does. I'm suspecting it's because you want to ignore normal escape characters but not certain ones that the re module uses. Is that right?

@davipo
Copy link

davipo commented Jan 21, 2015

You want a backslash in the string that you pass to the re.sub method, which interprets the "\b" as a boundary specifier. In a normal string, "\b" is a backspace character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants