+ 2

re.search return

So I am having an issue with python's regular expressions. I am attempting to filter out a user input so that only letters will print. However, if I use a=re.search and print(a.group()), i only get the first letter of the user input. Any thoughts or comments regarding my use or an alternative method to accomplish this task? also before any suggestions about using findall rather than search please note that findall returns a list instead of a string. I want to know how to return the string of just the letters in the program. import re pattern1 =r"[A-Za-z]" str=input() a=re.search(pattern1, str) print(a.group())

17th Oct 2017, 6:15 AM
Jesus Hernandez
Jesus Hernandez - avatar
1 Answer
+ 1
nevermind i found the answer @https://stackoverflow.com/questions/5618878/how-to-convert-list-to-string here is the revised code import re pattern1 =r"[A-Za-z]*" str1=input() a=re.findall(pattern1, str1) #print(type(a)) b = ''.join(a) print(a) print (b)
17th Oct 2017, 6:36 AM
Jesus Hernandez
Jesus Hernandez - avatar