首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从.txt文件中删除特殊字符会产生`LRB`、`LSB`、`RSB`、`LRB`、`RRB`等

从.txt文件中删除特殊字符会产生`LRB`、`LSB`、`RSB`、`LRB`、`RRB`等
EN

Stack Overflow用户
提问于 2016-05-31 10:46:39
回答 1查看 1K关注 0票数 2

我有一个.txt文件。实际上,我是通过读取URL和转换HTML文件得到的。我的.txt文件包含如此多的特殊字符。我只想保留英文单词。我用过,

代码语言:javascript
复制
`String result = listOfWords.replaceAll("[^a-zA-Z]+"," ");`

但是,输出会替换一些特殊字符,如LRBLSBRSBLRBRRB等。

例如:

代码语言:javascript
复制
Eleanor (2008), Mathematics

recent years. (TOP500 2006)^ Agatha C. Hughes (2000). Systems, Experts, and Computers. MIT Press. p. 161. ISBN 978-0-262-08285-3. The experience of SAGE helped make possible the first truly large-scale commercial real-time network: the SABRE computerized airline reservations system

替换后的结果为,

代码语言:javascript
复制
 Eleanor  LRB     RRB    Mathematics

recent years LRB TOP RRB Agatha C Hughes LRB RRB Systems Experts and Computers MIT Press p ISBN The experience of SAGE helped make possible the first truly large scale commercial real time network the SABRE computerized airline reservations system

如何解决这里的代码输入这个问题?

EN

回答 1

Stack Overflow用户

发布于 2016-06-01 05:04:06

您的正则表达式替换只会增加较大的间隙(空格)。LRB (左圆括号)和RRB (右圆括号)很可能来自您在regex替换之前所做的任何处理。如果您不关心特殊字符,您可能应该删除它们:

代码语言:javascript
复制
String result = listOfWords.replaceAll("[^a-zA-Z]+","");

正如@Emalka提到的,NLTK是quick 'HOWTO'的一个很好的来源。他们正在使用BeautifulSoup。因为你的问题谈到了Java,所以有一个很好的答案是使用Jsouphere on SO

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37536068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档