Matrixkid Posted May 22, 2009 Share Posted May 22, 2009 Hi there, I have a string that looks like this; 2-Name,3-Name,4-Name,5-Name,6-Name,7-name Im trying to preg_split the string into an array so that all im left with is name, I can remove the comma no problem once its split up I have tried the following: $array_name = preg_split("/[0-9][-]/",$names); $array_name = preg_split("/[0-9-]/",$names); $array_name = preg_split("/[0-9]-]/",$names); Thanks for your help! Cheers MK Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/ Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 This just gets "name", and takes the comma out as well. If you want to take the comma out yourself then remove ',?'. $names = "2-Name,3-Name,4-Name,5-Name,6-Name,7-name"; $array_name = preg_split("/,?\d-/",$names); print_r($array_name); ?> Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/#findComment-840171 Share on other sites More sharing options...
Matrixkid Posted May 22, 2009 Author Share Posted May 22, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/#findComment-840173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.