classification
Title: Find adverbs is not correct on the documentation
Type: behavior Stage: patch review
Components: Regular Expressions Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Rim Chatti, Sagnik Mazumder, docs@python, ezio.melotti, mrabarnett, peter.otten, rhettinger
Priority: normal Keywords: easy, patch

Created on 2020-07-09 16:42 by Rim Chatti, last changed 2020-08-04 07:52 by Sagnik Mazumder.

Pull Requests
URL Status Linked Edit
PR 21420 Rim Chatti, 2020-07-09 19:08
PR 21728 open Sagnik Mazumder, 2020-08-04 07:52
Messages (6)
msg373406 - (view) Author: Rim Chatti (Rim Chatti) Date: 2020-07-09 16:42
re.findall(r"\w+ly", text) does not find all adverbs in a sentence, it finds words that contain ly (not ending with ly) :
if text= 'andlying clearly', output: [andly, clearly]
which is wrong! 
the right way to do this is re.findall(r'\b(\w+ly)\b',text)
output= clearly!
msg373412 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-09 18:04
Please submit a PR.

The parenthesis are not needed:
   re.findall(r"\b\w+ly\b", text)
msg373422 - (view) Author: Rim Chatti (Rim Chatti) Date: 2020-07-09 19:08
re.findall(r"\w+ly", text) does not find all adverbs in a sentence, it finds words that contain ly (not ending with ly) :
if text= 'andlying clearly', output: [andly, clearly]
which is wrong! 
the right way to do this is re.findall(r'\b\w+ly\b',text)
output= clearly!
msg373426 - (view) Author: Peter Otten (peter.otten) * Date: 2020-07-09 20:03
While I don't want to start a philosical discussion -- is that really better? Finding adverbs with a regex doesn't work in the general case -- think butterfly, panoply, well -- and the example is meant to illustrate the usage of re.findall() rather than regex syntax.

"finding adverbs" is just shorter and easier to understand than "finding sequences of word characters that end with "ly".
msg373493 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-11 00:21
I think it's fine as-is.  The real purpose of the example is show basic patterns in writing regexes.  Pig-latin examples or searching for words ending in -ly make for nice beginner examples.   I like the OP's modification because it teaches a general skill (the importance of \b for making sure you get whole words).

We could add a link to the Natural Language Toolkit for people who are getting serious about searching for parts of speech.
msg374795 - (view) Author: Sagnik Mazumder (Sagnik Mazumder) * Date: 2020-08-04 07:52
fixed finding adverbs example in re docs
History
Date User Action Args
2020-08-04 07:52:41Sagnik Mazumdersetnosy: + Sagnik Mazumder

messages: + msg374795
pull_requests: + pull_request20871
2020-07-11 00:21:13rhettingersetmessages: + msg373493
2020-07-09 20:03:27peter.ottensetnosy: + peter.otten
messages: + msg373426
2020-07-09 19:08:45Rim Chattisettype: behavior
components: + Regular Expressions, - Documentation

keywords: + patch
nosy: + mrabarnett, ezio.melotti
stage: patch review
messages: + msg373422
pull_requests: + pull_request20569
2020-07-09 18:04:24rhettingersetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.5
nosy: + rhettinger

messages: + msg373412

keywords: + easy
2020-07-09 16:43:10Rim Chattisettitle: Find adverbs is not correct -> Find adverbs is not correct on the documentation
2020-07-09 16:42:02Rim Chatticreate