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
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post

    Question Regex remove whiteSpace (in combination with non alphanumeric)

    I've got this regex to remove all non alphanumeric characters from a string:

    PHP Code:
    preg_replace("/[^A-Za-z0-9 ]/"''$string); 
    But I want to remove all whitespaces (space) as well from the same string.

    How can I alter my regex so that all whitespaces are removed as well ?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Just a one character change to do that:

    PHP Code:
    preg_replace("/[^A-Za-z0-9]/"''$string); 
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    docock (01-28-2014)

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post
    Thanks, that helped me a lot!


  •  

    Posting Permissions

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