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

23rd Jan 2023, 10:32 PM
Alan Restrepo
Alan Restrepo - avatar
16 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
24th Jan 2023, 5:45 AM
Chris Coder
Chris Coder - avatar
+ 3
s='@A#l4an>5 Res6tr9ep7o%$#' print(re.sub('[^a-zA-Z ','',s))
23rd Jan 2023, 11:40 PM
Jay Matthews
Jay Matthews - avatar
+ 2
import re pattern = r'[[email protected]#$%^&*()_+-=,.<>/?;:\'\"\\|`~]' d = input() y = (re.findall(pattern, d)) x = ''.join(y) print(x)
25th Jan 2023, 12:07 AM
Walter joseph
Walter joseph - avatar
+ 1
Alan Restrepo The second parameter in the re.sub() is 2 single quotes(') with no space between them. https://code.sololearn.com/cR0Y9uWrgZBh/?ref=app
24th Jan 2023, 1:25 AM
Jay Matthews
Jay Matthews - avatar
+ 1
Alan Restrepo Try it now.
24th Jan 2023, 4:48 AM
Jay Matthews
Jay Matthews - avatar
0
[0-9]+ should work in the regex to find all the numbers
23rd Jan 2023, 10:45 PM
Ausgrindtube
Ausgrindtube - avatar
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
23rd Jan 2023, 11:12 PM
Alan Restrepo
Alan Restrepo - avatar
0
Jay Matthews i think the print part is not complete because is not working
23rd Jan 2023, 11:50 PM
Alan Restrepo
Alan Restrepo - avatar
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?
24th Jan 2023, 4:24 AM
Alan Restrepo
Alan Restrepo - avatar
0
Jay Matthews i try it and works, but you now how to make it apear lik this: hello world
24th Jan 2023, 5:09 AM
Alan Restrepo
Alan Restrepo - avatar
0
Chris Coder thanks for the code man, crist bless you, i appreciate it
24th Jan 2023, 6:05 AM
Alan Restrepo
Alan Restrepo - avatar
0
Jay Matthews thanks for the help, crist bless you
24th Jan 2023, 6:06 AM
Alan Restrepo
Alan Restrepo - avatar
0
You are welcome Alan Restrepo Thanks for giving us the oppertunity to help. - Happy Coding!
24th Jan 2023, 6:08 AM
Chris Coder
Chris Coder - avatar
0
Int/;join int:inline printf
25th Jan 2023, 12:05 AM
Who Ami
0
Thanks a lot for the code matthews i appreciate it
25th Jan 2023, 12:06 AM
Who Ami
0
s = "#h$e%[email protected] w#[email protected]@*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)
25th Jan 2023, 5:10 PM
Smith Welder
Smith Welder - avatar