c# Regex删除某些特定选项卡后的句子

本文关键字:选项 句子 Regex 删除 | 更新日期: 2023-09-27 18:02:47

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

我的文本在richtextbox
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之后,应该省略句子(I -e its gloss),然后在另一个单词able#1之后,它的gloss应该省略。

它的正则表达式是什么,以删除sentiwordnet文本文件中单词的光泽。有什么方法可以做到这一点,或者有人可以让我一个小样本/无效?

输出应该是这样的:

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

c# Regex删除某些特定选项卡后的句子

应该可以了

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");

您可以查找#后面跟着数字,因此正则表达式将是

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

[^#]*将匹配0到除#

之外的许多字符

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

$表示字符串

的结束

't[^'t]+$

可以使用regex

的replace函数
input=Regex.Replace(input,regex,"");