function getNames($names){
foreach ($names as $key => $name) {
$ysname = $name;
$name = str_replace(')',')', $name);
$name = str_replace('(','(', $name);
$name = str_replace(' ',' ', $name);
$name = trim( $name );
$name = trim( $name , ',' );
if($name == '') continue;
$str = $name;
$tempReg = [];
for($i=0;$i<strlen($name);$i++){
$lastReg = end($tempReg);
$lastRegIndex = count($tempReg) - 1;
if(preg_match('/^[\x{4e00}-\x{9fa5}].*?/u',$str)){
$str = substr($str, 3);
if($lastReg == '([\x{4e00}-\x{9fa5}])'){
$tempReg[ $lastRegIndex ] = '([\x{4e00}-\x{9fa5}]{2})';
}else if( preg_match('/9fa5\}\]\{(\d+)\}\)$/', $lastReg , $match ) ){
$tempReg[ $lastRegIndex ] = '([\x{4e00}-\x{9fa5}]{'. ( $match[1] + 1 ) .'})';
}else{
$tempReg[] = '([\x{4e00}-\x{9fa5}])';
}
$i = $i + 2;
}else if(preg_match('/^、.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(、)';
$i = $i + 2;
}else if(preg_match('/^(.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(()';
$i = $i + 2;
}else if(preg_match('/^).*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '())';
$i = $i + 2;
}else if(preg_match('/^ .*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '( )';
$i = $i + 2;
}else if(preg_match('/^:.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(:)';
$i = $i + 2;
}else if(preg_match('/^,.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(,)';
$i = $i + 2;
}else if(preg_match('/^;.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(;)';
$i = $i + 2;
}else if(preg_match('/^【.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(【)';
$i = $i + 2;
}else if(preg_match('/^】.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(】)';
$i = $i + 2;
}else if(preg_match('/^。.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(。)';
$i = $i + 2;
}else if(preg_match('/^#.*?/u',$str)){
$str = substr($str, 3);
$tempReg[] = '(#)';
$i = $i + 2;
}else if(preg_match('/^[a-zA-Z].*?/',$str)){
$str = substr($str, 1);
if($lastReg == '([a-zA-Z])'){
$tempReg[ $lastRegIndex ] = '([a-zA-Z]{2})';
}else if( preg_match('/^\(\[a-zA-Z\]\{(\d+)\}\)$/', $lastReg , $match ) ){
$tempReg[ $lastRegIndex ] = '([a-zA-Z]{'. ( $match[1] + 1 ) .'})';
}else{
$tempReg[] = '([a-zA-Z])';
}
}else if(preg_match('/^\d.*?/',$str)){
$str = substr($str, 1);
if($lastReg == '(\d)'){
$tempReg[ $lastRegIndex ] = '(\d{2})';
}else if( preg_match('/\(\\\d\{(\d+)\}\)$/', $lastReg , $match ) ){
$tempReg[ $lastRegIndex ] = '(\d{'. ( $match[1] + 1 ) .'})';
}else{
$tempReg[] = '(\d)';
}
}else if(preg_match('/^_.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(_)';
}else if(preg_match('/^-.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(-)';
}else if(preg_match('/^\(.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\()';
}else if(preg_match('/^\).*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\))';
}else if(preg_match('/^\..*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\.)';
}else if(preg_match('/^\[.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\[)';
}else if(preg_match('/^\].*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\])';
}else if(preg_match('/^\/.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(\/)';
}else if(preg_match('/^,.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(,)';
}else if(preg_match('/^:.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(:)';
}else if(preg_match('/^;.*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(;)';
}else if(preg_match('/^ .*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '( )';
}else if(preg_match('/^#*?/',$str)){
$str = substr($str, 1);
$tempReg[] = '(#)';
}else if(preg_match('/^·.*?/',$str)){
$str = substr($str, 2);
$tempReg[] = '(·)';
$i = $i + 1;
}else{
var_dump($ysname);
echo $str . " weizhi\n";
var_dump($str);
$tempReg[] = '(未知)';
}
}
$tempReg = implode('', $tempReg);
$allRegData[$tempReg][] = $ysname;
}
return $allRegData;
}
上述代码的功能主要是对数量较大、单条字符长度不长的文字进行正则表达式分类归纳。