-1

I've written the following regex to capture every word ending with "d":

suffix_reg_1 = re.findall(r"(\b\w+d(?=\s))", sample_list)

The regex itself seems to work fine in RegexBuddy (Python 3.8 flavour), but in Python my list remains empty when running above. Any idea why?

Originally I wrote this regex...

\b\w+d\b

which works fine in Python, but as soon as I add capturing groups...

(\b\w+)(d\b)

I have the same problem again:: empty list. Again, in RegexBuddy it works fine, even with capturing groups.

Zweible
  • 1
  • 2
  • `re.findall(r"\b\w+d\b", sample_list)` will do. Do not add groups here, as [`re.findall` behaves weird](https://stackoverflow.com/questions/31915018/re-findall-behaves-weird). – Wiktor Stribiżew May 23 '21 at 21:58
  • Thanks, but I need a group - I need to later remove the suffix – Zweible May 23 '21 at 22:07
  • Then please ask the question you need to answer. `re.findall` does not remove anything. – Wiktor Stribiżew May 23 '21 at 22:08
  • I need a regex that captures all words ending with "d" that will then let me replace the "d" with nothing. My approach would have been to put the "d" in a capturing group so that I could then replace it with nothing. These modified words without the "d" at the end need to be saved to a list. – Zweible May 23 '21 at 22:14
  • What a complicated plan. Use `re.findall(r"\b(\w+)d\b", sample_list)` – Wiktor Stribiżew May 23 '21 at 22:21
  • indeed it is ... thanks, this works nicely. – Zweible May 23 '21 at 22:29

0 Answers0