Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2010, 03:25 AM   PM User | #1
ynotlim
Regular Coder

 
Join Date: Sep 2006
Posts: 131
Thanks: 5
Thanked 0 Times in 0 Posts
ynotlim is an unknown quantity at this point
keep only A-Z , 1-9 characters in Python

hello,

I have a string and I want to strip all the odd characters from it and keep only A-Z,1-9.

How do i do that?

ie.

test = asdf@$%aasdf..{}}.jpg
test.keep(a-z,1-9)
test = asdfaasdfjpg

Thanks!

Tony
__________________
---------
Client / Server Side Programmer II
ynotlim is offline   Reply With Quote
Old 08-05-2010, 01:06 PM   PM User | #2
Kakao
Regular Coder

 
Join Date: Mar 2006
Location: Brasília, Brazil
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
Kakao is on a distinguished road
Code:
import re
pattern = '[a-zA-Z0-9]'
input = 'asdf@$%aasdf..{}}.jpg'
output = ''.join(re.findall(pattern, input))
Kakao is offline   Reply With Quote
Old 08-05-2010, 08:59 PM   PM User | #3
ynotlim
Regular Coder

 
Join Date: Sep 2006
Posts: 131
Thanks: 5
Thanked 0 Times in 0 Posts
ynotlim is an unknown quantity at this point
sweet thanks! worked like a charm
__________________
---------
Client / Server Side Programmer II
ynotlim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:27 AM.


Advertisement
Log in to turn off these ads.