python提取字符串中的 中文 日文 韩文

import imp
imp.reload(sys)
 
s=""" 
 en: Regular expression is a powerful tool for manipulating text. 
 zh: 汉语是世界上最优美的语言,正则表达式是一个很有用的工具 
 jp: 正規表現は非常に役に立つツールテキストを操作することです。 
 jp-char: あアいイうウえエおオ 
 kr:정규 표현식은 매우 유용한 도구 텍스트를 조작하는 것입니다. 
 """ 
print ("原始utf8字符" )
#utf8 
print ("--------" )
print( repr(s) )
print( "--------\n" )
原始utf8字符
--------
' \n en: Regular expression is a powerful tool for manipulating text. \n zh: 汉语是世界上最优美的语言,正则表达式是一个很有用的工具 \n jp: 正規表現は非常に役に立つツールテキストを操作することです。 \n jp-char: あアいイうウえエおオ \n kr:정규 표현식은 매우 유용한 도구 텍스트를 조작하는 것입니다. \n '
--------

非ansi

#非ansi 
re_words=re.compile(r"[\x80-\xff]+") 
#m = re_words.search(s,0) 
m1=re.findall(re_words, s)


print ("非ansi字符" )
print ("--------" )
print (m1 )
#print (m.group() )
print ("--------\n" )
非ansi字符
--------
[]
--------

中文

re_words = re.compile(u"[\u4e00-\u9fa5]+") 
#m = re_words.search(s) 
m1=re.findall(re_words, s)
#print(''.join(m1))
print( "unicode 中文" )
print(m1)
print( "--------" )
unicode 中文
['汉语是世界上最优美的语言', '正则表达式是一个很有用的工具', '正規表現', '非常', '役', '立', '操作']
--------

韩文

 
#unicode korean 
re_words=re.compile(u"[\uac00-\ud7ff]+") 
#m = re_words.search(s,0) 
m1=re.findall(re_words, s)
print( "unicode 韩文" )
print(m1)
print( "--------\n" )
unicode 韩文
['정규', '표현식은', '매우', '유용한', '도구', '텍스트를', '조작하는', '것입니다']
--------

日文 片假名

#unicode japanese katakana 
re_words=re.compile(u"[\u30a0-\u30ff]+") 
#m = re_words.search(s,0) 
m1=re.findall(re_words, s)
print( "unicode 日文 片假名" )
print ("--------" )

print(m1)
print( "--------\n" )
unicode 日文 片假名
--------
['ツールテキスト', 'ア', 'イ', 'ウ', 'エ', 'オ']
--------

日文 平假名

#unicode japanese hiragana 
re_words=re.compile(u"[\u3040-\u309f]+") 
#m = re_words.search(s,0) 
m1=re.findall(re_words, s)
print( "unicode 日文 平假名" )
print ("--------" )

print(m1)
print( "--------\n" )
unicode 日文 平假名
--------
['は', 'に', 'に', 'つ', 'を', 'することです', 'あ', 'い', 'う', 'え', 'お']
--------

标点符号

#unicode cjk Punctuation 
re_words=re.compile(u"[\u3000-\u303f\ufb00-\ufffd]+") 
#m = re_words.search(s,0) 
m1=re.findall(re_words, s)
print( "unicode 标点符号" )
print ("--------" )

print(m1)
print( "--------\n" )
 
unicode 标点符号
--------
[',', '。']
--------
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值