0

如何编写正则表达式以删除某些特定选项卡后的句子?

例如富文本框中的我的文本

a   00001740    0.125   0   able#1  (usually followed by `to') having the necessary means or skill or know-how or authority to do something; "able to swim"; "she was able to program her computer"; "we were at last able to buy a car"; "able to get a grant for the project"
a   00002098    0   0.75    unable#1    (usually followed by `to') not having the necessary means or skill or know-how; "unable to get to town without a car"; "unable to obtain funds"
a   00002312    0   0   dorsal#2 abaxial#1  facing away from the axis of an organ or organism; "the abaxial surface of a leaf is the underside or side facing away from the stem"  

本文来自 sentiwordnet。我想在第五个选项卡之后删除句子,例如应该省略单词able#1 句子(即它的光泽),然后在另一个单词无法#1 之后,它的光泽应该被省略。

什么将是它的正则表达式来消除 sentiwordnet 文本文件中单词的光泽。有什么办法可以做到这一点,或者有人可以为我制作一个小样本/空白吗?

输出应该是这样的:

a   00001740    0.125   0   able#1
a   00002098    0   0.75    unable#1
a   00002312    0   0   dorsal#2 abaxial#1
4

2 回答 2

0

您可以改为查找 # 后跟数字..所以正则表达式将是

(?<=#\d+)[^#]*$

[^#]*将匹配 0 到许多字符,除了 #

(?<=#\d+)将检查特定模式(# 后跟数字)是否在匹配之前出现[^#]*

$描述字符串的结尾

或者

\t[^\t]+$

您可以使用正则表达式的替换功能

input=Regex.Replace(input,regex,"");
于 2013-03-06T14:30:10.277 回答
0

这应该做的工作

string text = @"a   00001740    0.125   0   able#1  (usually followed by `to') having the necessary means or skill or know-how or... ";

string res = Regex.Replace(text, @"((?:[^\t]+\t){5}).+$", "$1");
于 2013-03-06T14:34:32.823 回答