0

why i cannot do pattern = r"(.+) /2" in "word word word"?

it gives error. what it means /2, or /3?

7th Aug 2016, 9:14 PM
Benedek Måté Tóth
Benedek Måté Tóth - avatar
4 Answers
+ 1
\2 means "the same as the second group". Your expression defines only one group, therefore you cannot use \2. Ps: beware the syntax you have to use \ not / !
14th Aug 2016, 4:45 PM
MAP91
+ 1
So, for completeness to answer the question, you want to do r"(.+?) \1 \1". Notice the ? after it so as to use a "lazy" match and stop at the first space. Also if you only want letters, try r"([a-zA-Z]+?) \1 \1". This would match a character set of only letters. It's generally best practice to be as specific in what you're after as possible, and only use . if you really are okay with anything except a newline
21st Aug 2016, 4:34 PM
Terry Weiss
Terry Weiss - avatar
0
oh, thank you:) now it is clear:)
15th Aug 2016, 9:02 AM
Benedek Måté Tóth
Benedek Måté Tóth - avatar
0
try \2
30th Aug 2016, 7:51 PM
beauty1234