Results 1 to 2 of 2

Thread: Help with regular expression

  1. #1
    Join Date
    Feb 2010
    Posts
    19

    Help with regular expression

    I am using the split() function and I need a regular expression I can't quite remember how to do.

    I want to check if there is a space, a tab, OR space AND tab. One of the following.

    The following treats it as 2 different things.
    $array = split ("[ \t]", $line);

    So if the line = Hello(space)(tab)World

    It will return 3 array nodes which are "Hello", "", World

    I want it to only return "Hello", "World" no matter if the line is:

    line = Hello(space)World
    or
    line = Hello(tab)World
    or
    line = Hello(space)(tab)World

    Any ideas? thanks

  2. #2
    Join Date
    Sep 2011
    Location
    London, UK
    Posts
    60
    PHP Code:
    function splitBySpace($text){
        return 
    explode(' 'preg_replace('{\s+}'' '$text));

    It works for any number of spaces, tabs and even new lines.

Similar Threads

  1. Expression Studio, enough to get started?
    By CARRBOMB in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 04 Apr 2009, 10:37 PM
  2. regular expression
    By sm9ai in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 13 Apr 2006, 02:35 AM

Posting Permissions

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