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

\b requires raw strings or to be escaped. Update docs with that hint? #73501

Closed
mlissner mannequin opened this issue Jan 18, 2017 · 2 comments
Closed

\b requires raw strings or to be escaped. Update docs with that hint? #73501

mlissner mannequin opened this issue Jan 18, 2017 · 2 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@mlissner
Copy link
Mannequin

mlissner mannequin commented Jan 18, 2017

BPO 29315
Nosy @bitdancer, @mlissner

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2017-01-18.21:11:54.303>
created_at = <Date 2017-01-18.20:21:15.511>
labels = ['invalid', 'type-feature', '3.7', 'docs']
title = '\\b requires raw strings or to be escaped. Update docs with that hint?'
updated_at = <Date 2017-01-18.21:11:54.301>
user = 'https://github.com/mlissner'

bugs.python.org fields:

activity = <Date 2017-01-18.21:11:54.301>
actor = 'r.david.murray'
assignee = 'docs@python'
closed = True
closed_date = <Date 2017-01-18.21:11:54.303>
closer = 'r.david.murray'
components = ['Documentation']
creation = <Date 2017-01-18.20:21:15.511>
creator = 'Mike.Lissner'
dependencies = []
files = []
hgrepos = []
issue_num = 29315
keywords = []
message_count = 2.0
messages = ['285751', '285755']
nosy_count = 3.0
nosy_names = ['r.david.murray', 'docs@python', 'Mike.Lissner']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue29315'
versions = ['Python 2.7', 'Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7']

@mlissner
Copy link
Mannequin Author

mlissner mannequin commented Jan 18, 2017

I just ran into a funny corner case I imagine others are aware of. When you write "\b" in Python, it is a single character: "\x08". So if you try to write a regex like:

words = '\b(.*)\b'

That won't work. But using a raw string will:

words = r'\b(.*)\b'

As will escaping it in this horrible fashion:

words = '\\b(.*)\\b'

I believe this doesn't affect any of the other regex flags, so I wonder if it's worth adding something to the docs to warn about this. I just spent a bunch of time trying to figure out why it seemed like \b wasn't working. A little tip in the docs would have gone a LONG way.

@mlissner mlissner mannequin added the 3.7 (EOL) end of life label Jan 18, 2017
@mlissner mlissner mannequin assigned docspython Jan 18, 2017
@mlissner mlissner mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jan 18, 2017
@bitdancer
Copy link
Member

One should always use raw strings for regex expressions, and this is already documented in the introduction to the regex module. Further, in 3.5 using \ in front of characters that aren't special produces a warning, which should reduce the frequency of this mistake.

I don't see that there's anything to do here.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant