Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    import re
    pattern = '[a-zA-Z0-9]'
    input = 'asdf@$%aasdf..{}}.jpg'
    output = ''.join(re.findall(pattern, input))

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    sweet thanks! worked like a charm
    ---------
    Client / Server Side Programmer II


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •