匹配中文标点符号:

String str='[u3002uff1buff0cuff1au201cu201duff08uff09u3001uff1fu300au300b]'

该表达式可以识别出: 。 ;  , : “ ”( ) 、 ? 《 》 这些标点符号。

匹配中文汉字

String str='[u4e00-u9fa5]';

该表达式可以识别出任何汉字。

例子:
[php]
$origin_text=’京港台:2014-10-13 18:20 来源:人民网’
$pattern="/x{FF1A}[x{3000}x{feff}x20]?([x{3002}x{ff1b}x{ff0c}x{ff1a}x{201c}x{201d}x{ff08}x{ff09}x{3001}x{ff1f}x{300a}x{300b}x{4e00}-x{9fa5}a-zA-Z0-9]*)/u";

$origin=”;
if(preg_match_all($pattern,$origin_text,$matches)){
//print_r($matches);
if(!empty($matches[2][1])){
$origin=$matches[2][1];
}else{
$origin=$matches[1][1];
}
}
[/php]

Advertisements
Posted in PHP

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s