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"  

このテキストはセンチワードネットからのものです。5番目のタブの後の文を削除したいのですが、単語able#1の後に文を省略し(つまり、そのグロス)、別の単語unable#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

これは仕事をするはずです

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 に答える
0

代わりに # の後に数字を探すことができます..したがって、正規表現は次のようになります

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

[^#]*0 から # を除く多くの文字に一致します

(?<=#\d+)一致する前に、特定のパターン (# の後に数字が続く) が発生するかどうかを確認します[^#]*

$文字列の終わりを示します

また

\t[^\t]+$

正規表現の置換機能を使用できます

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