[thelist] Regex remove repeats

Chris Heilmann lists at onlinetools.org
Wed Jan 26 05:50:09 CST 2005


> Hi all
>
> I've got a large amount of repeating data that I need to strip down so
> that there's only one instance of each name.  For example, I've got:
>
> ac/dc,ac/dc,ac/dc,ac/dc,david bowie,david bowie,dixie chicks,dixie
> chicks,black sabbath,zz top,zz top,zz top,zz top
>
> I'm stuck on writing a regex that is going to lok ahead to see if the
> next item in the comma separated list is the same as the last and, if it
> is, to remove it.


I doubt that regex could do it, I think you need to loop through it.
If you use PHP, then array_unique is your mate:
$values=explode(',','ac/dc,ac/dc,ac/dc,ac/dc,david bowie,david bowie,dixie
chicks,dixie chicks,black sabbath,zz top,zz top,zz top,zz top');
$values=array_unique($values);
print_r($values);

http://uk2.php.net/manual/en/function.array-unique.php




-- 
Chris Heilmann
http://icant.co.uk/ | http://www.onlinetools.org/



More information about the thelist mailing list