博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用正则表达式分离汉字、英文、数字
阅读量:7016 次
发布时间:2019-06-28

本文共 806 字,大约阅读时间需要 2 分钟。

在中文分词的过程中需要将英文,数字,汉字分离,数字和英文就不用分割了,主要是将分离出来的汉字进行分词,下面的算法实现利用正则表达式分离汉字、英文、数字:

//获取中文string chRegS = @"[\u4e00-\u9fa5]+";Regex chRegR = new Regex(chRegS);Match chMacth = chRegR.Match(str);while(chMacth.Success){     CHresult.Add(chMacth.ToString());     chMacth = chMacth.NextMatch();}//英文string enRegS = @"[a-zA-Z]+";Regex enRegR = new Regex(enRegS);Match enMatch = enRegR.Match(str);while (enMatch.Success){     Enresult.Add(enMatch.ToString());     enMatch = enMatch.NextMatch();}//数字string numRegS = @"\d+";Regex numRegR = new Regex(numRegS);Match numMatch = numRegR.Match(str);while (numMatch.Success){     Numresult.Add(numMatch.ToString());     numMatch = numMatch.NextMatch();} 转自
 

 

测试字符串:“可复用的WPF或者Silverlight应用程序和组件设计(3)——控件级别”

 

结果:

 

 

转载于:https://www.cnblogs.com/zcm123/archive/2012/08/30/2663741.html

你可能感兴趣的文章
上学路线
查看>>
相对路径 System.Web HttpServerUtilityBase Server.MapPath("~/")
查看>>
【转】Spring中事务与aop的先后顺序问题
查看>>
IIS服务器管理学习
查看>>
poj3252-Round Number 组合数学
查看>>
程序猿和星座之间不可不谈的事
查看>>
log4j.properties 日志分析
查看>>
pdfminer import报错解决方法
查看>>
测试用例大全
查看>>
装饰者模式
查看>>
如何修改WAMP中mysql默认空密码
查看>>
Java内存区域和GC机制篇
查看>>
linux中的strings命令
查看>>
CentOS7/64位环境安装Mysql 5.7.19二进制包教程
查看>>
BitArray
查看>>
c++ function template
查看>>
mybatis做like模糊查询
查看>>
如果你建造了一个精良的模型却没人用,你肯定不会得到赞誉(转)
查看>>
AOP 专题
查看>>
[TCP/IP] 传输层-TCP和UDP的使用场景
查看>>