【发布时间】:2013-08-20 06:36:47
【问题描述】:
我正在从字符串中删除特定的字符串。首先我通过文件阅读器读取文本文件,然后我将文件的内容存储到字符串数组中并从字符串数组中删除一些特定的字符串
我的输入文本是:
:VL
15
n
3 c
09:0.023
15th:0.023
1987:0.025
1st:0.025
2:0.013
2.0:0.043
2003:0.056
2005:0.056
Top Terms:
Weight :
props
optional
: Point:
1.0:
15th:0.068
现在我正在阅读此文本并将其存储到字符串数组中:String [] Result
我的代码:
for(String t1: Result){
Pattern = Pattern.compile("\\b:[0-9]\\b");
matcher = pattern.matcher(t1);
if(matcher.find()){
System.out.println(t1);
}
和 输出 我得到了:
09:0.023
15th:0.023
1987:0.025
1st:0.025
2:0.013
2.0:0.043
2003:0.056
2005:0.056
Top Terms:
Weight :
15th:0.068
但是我不想要这个输出。我的输出应该是这样的:
09:0.023
15th:0.023
1987:0.025
1st:0.025
2:0.013
2.0:0.043
2003:0.056
2005:0.056
15th:0.068
请告诉我我必须应用什么正则表达式才能获得此输出。
【问题讨论】:
-
我认为您需要删除没有任何数字的字符串
-
告诉我正则表达式删除没有任何数字的字符串。
-
我怀疑
"2005:0.056 Top Terms: Weight :"实际上可能是一行。