Why it capture only "word", but not all the string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why it capture only "word", but not all the string

import re pattern = r"(.+) \1" match = re.match(pattern, "word word") if match: print ("Match 1") In Powershell the pattern above will capture all the string, because metasymbol ". " is captures anym symbol, so the match. groups() should be "word word", but not "word"

17th Apr 2018, 1:54 PM
Pavel Kandratsyeu
Pavel Kandratsyeu - avatar
4 Answers
+ 1
Because the space is in the pattern. I understand you searching all characters on the left of a space. The result is "world".
18th Apr 2018, 4:04 PM
jerome
0
There is a space in you pattern. What's append if you remove it?
18th Apr 2018, 3:03 PM
jerome
0
So, this is the question, why it doesn't captute space...
18th Apr 2018, 3:55 PM
Pavel Kandratsyeu
Pavel Kandratsyeu - avatar
0
I didn't see the space.... Thank you very much for the help.
18th Apr 2018, 4:09 PM
Pavel Kandratsyeu
Pavel Kandratsyeu - avatar