I wanted to extract lovely and real ending with ly from sentence.
Doesn't r'\D+ly'
become 'repeat non-numeric (\D
) several times (+
), and find a pattern that ends with ly
'?
But I wonder why the result was different from r'\w+ly'
.
r'\w+ly'
thinks that even if the letter or number (\w
) is repeated many times (+
), find a pattern that ends with ly
', so I think the right result came out.
Shouldn't r'\D+ly'
also have ['lovely', 'really']
?
I'm curious
Thank you for reading.
python
Because \D
contains spaces and \w
does not contain spaces. https://regex101.com/r/W91E8U/1
© 2025 OneMinuteCode. All rights reserved.