Tuesday, July 20, 2010

Regular expression to filter special characters and prefixed numbers from a string

            $search_pattern = array ( "/^(-|\s|_|[0-9])+/", 
                                                 "/(-|\s|_|\.|\&)+/e",
                                                 "/(\w+)_(MP3|mp3)+/",);
            $replace = array ("", "_", "$1.$2");


            $string = "- 10_unnaithane.  ---  than...jam____1099_SPB1 & Janaki.mp3";

            echo preg_replace($search_pattern, $replace, $string);

Output :

            unnaithane_than_jam_1099_SPB1_Janaki.mp3





Ref : http://www.webcheatsheet.com/php/regular_expressions.php



No comments:

Post a Comment