I have a text file that I am trying to parse to pull information into an array.. the text file is just a property listing that the Dept. of Veteran Affairs puts out, so it is not a flat file (tab or comma delimited, etc).

However, the information that I want to grab is all separated by numerous spaces (not a set number).

I am using this regular expression to replace any series of two or more spaces with a "|" character so that I can then explode() the string into an array:

$record_container[$c] = ereg_replace("[ ][ ]+", "|", $record_container[$c]);

The problem is that I really need it to catch series of THREE or more spaces, not two -- and I know little to nothing about regular expressions.. figuring that one out was an act of god and when I try to just add another "[ ]" it goes weird on me.

What expression should I use to replace a series of three or more spaces with a pipe?

Any help is much appreciated..

  • sexy

P.S. - If it helps any, this is the file that I am trying to parse: http://www.vba.va.gov/ro/atlanta/rlc/pm/gaproper.htm

    I think this might work:

    $record_container[$c] = ereg_replace("[ ]{3,}", "|", $record_container[$c]);

      have you tried preg_split?
      it would save you the exploding ...

      $keywords = preg_split ("/[\\s]+/", $string);
      
        Write a Reply...