Regular expression: preg_match_all()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dimpie
    New Member
    • Jan 2007
    • 1

    #1

    Regular expression: preg_match_all()

    I've created a form where visitors can input more than one value. They have to use a space as a delimiter. For example: 'mozart beethoven grieg'.
    And redundant spaces should be converted to one space.

    The only exception is when a value is followed by a comma and a space.
    Then the search string should be taken literally.

    So if for example you filled in:
    mozart amadeus, then this should be split into:
    'mozart' and 'amadeus'.
    But if you filled in 'mozart, amadeus' it should stay 'mozart, amadeus'.

    These values shoud be seperated in put into an array.
    So if someone filled in: mozart grieg, beethoven bach.
    I would have an array with the values:
    array[0] = mozart
    array[1] = grieg, beethoven
    array[2] = bach

    Code:
    preg_match_all('/[^\s]+/', $persoon, $m); 
        $array_persoon = $m[0];
    Is it possible to adjust the preg_match_all( ) function so that it doensn't use (comma space) as a separator?

    Thanks in advance,
    Dimpie
Working...