#1
  1. No Profile Picture
    Spontaneously Present
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2005
    Posts
    1,149
    Rep Power
    0

    Remove more than 2 spaces but keep atleast one


    simply want to keep atleast one space out of many, and if atleast one already exists then dont take it out.

    e.g.

    string:
    Code:
    string string    string
    Regex:
    Code:
    /\s{2}/
    Result:
    Code:
    string stringstring
    Expected:
    Code:
    string string string
  2. #2
  3. No Profile Picture
    Spontaneously Present
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2005
    Posts
    1,149
    Rep Power
    0
    crap nvm


    /\s+/
  4. #3
  5. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by mwild8
    crap nvm


    /\s+/
    Note that such a regex will also replace new line characters. To replace 2 or more spaces (or tabs) with a single space, you could do this (in Perl):

    Code:
    $str =~ s/[ \t]{2,}/ /g;

    Comments on this post

    • mwild8 agrees : thanks!

IMN logo majestic logo threadwatch logo seochat tools logo