0
Hi i need some help right here
this is my code: pattern = r'[\w\s]' d = input() y = (re.findall(pattern, d)) x = ''.join(y) print(x) i need that if the user introduce some thing like this: @h?e*l%l1o w#o2r^l3d my program take off the especial keys(@!#$%*&) and the numbers. The program showed above take off the especial keys but not the numbers and that's the reason why i need some help. I don't know how to make the program delete the numbers. if some one could help it would be awesome
13 Answers
+ 1
Hi Alan Restrepo it looks like Jay Matthews is on the right track. I modified their code to give the results you seek.
https://code.sololearn.com/c7JNkRdcK0au/?ref=app
+ 2
import re
pattern = r'[0-9!@#$%^&*()_+-=,.<>/?;:\'\"\\|`~]'
d = input()
y = (re.findall(pattern, d))
x = ''.join(y)
print(x)
+ 1
[0-9]+ should work in the regex to find all the numbers
0
Ausgrindtube i use your code and didn't worked, the out put that im looking for is some thing like this:
input example:
@h#e3l4l&o w2o#r*l$d
out put example:
hello world
0
Jay Matthews i think the print part is not complete because is not working
0
Jay Matthews i use your code now and worked. if the letters in the s variable are back wards how can i make that the letters be printed in the right order?
0
Jay Matthews i try it and works, but you now how to make it apear lik this:
hello world
0
Chris Coder thanks for the code man, crist bless you, i appreciate it
0
Jay Matthews thanks for the help, crist bless you
0
You are welcome Alan Restrepo Thanks for giving us the oppertunity to help. - Happy Coding!
0
Int/;join int:inline printf
0
Thanks a lot for the code matthews i appreciate it
0
s = "#h$e%llo@ w#o@@*r**#l#d$quot;
for u in s:
if u.isalnum() or u==' ':
print(u,end="")
or so..
print()
print("".join((u for u in s if u.isalnum() or u==' ')))
or so..
print("".join(filter(lambda u: u.isalnum() or u== ' ', s)))
or etc..
use help() function if you dont know or dont remember something
for example
help(str)