0

re.findall not picking up some words

After a post I'd seen on here, I tried to use the suggestion (finding double vowel words e.g (wood, sleep) into a code I've done so time back, but i wanted to return every double letter word e.g ...hello, setter, getter etc. My original code does do what I need, but using the new "pattern" some words are not being "found". My string has some random double letter words...just for testing. https://code.sololearn.com/co0CKJ19q42w/#py If you do reply and I don't get back to you ...sorry...it's late and I'm off to bed but I will respond tomorrow. Thank you in advanced.

6th Apr 2020, 10:38 PM
rodwynnejones
rodwynnejones - avatar
2 ответов
+ 5
Your regex uses the string "string.ascii_letters" itself as the pattern, not the value of the variable (i.e. the lowercase/uppercase letters). It matches the characters "s", "t", "r", "i", "n", "g", ".", "a", "c", "_", "e". You can solve this using string interpolation: pattern = rf'([{string.ascii_letters}])\1' Or using regex notation: pattern = r'[a-zA-Z]'
6th Apr 2020, 11:16 PM
Diego
Diego - avatar
+ 2
ahh...I see......thank you for the solution(s),.... it makes sense now.
7th Apr 2020, 4:39 PM
rodwynnejones
rodwynnejones - avatar