2011-12-15 73 views
-2

我需要一个正则表达式,可以从下面的文字中进行选择:拒绝线,时间

string test hello world! 
    bitmap player player.png 
terrain(test) 
bg(sky) 
label(asdasd,sd, sd,ad,adsad, ds){sdds} 
00:30 test(asda,asdad,adsd)asdad{asd} 
    02:30 test(asda,asdad,adsd)asdad 
00:40 test(asda,asdad,adsd)asdad 

返回以下组:

{ 
"string test hello world!", 
"bitmap player player.png", 
"terrain(test)", 
"bg(sky)", 
"label(asdasd,sd, sd,ad,adsad, ds){sdds}" 
} 

我想用..:..避免的时间。

非常感谢。

我试图

(?<!\b..:..\s).* 

,但没有工作。

+0

我会逐行读取输入内容,然后可以丢弃符合我们标准的输入内容;即:`^ \ s * \ d \ d:\ d \ d` – mpen 2011-12-15 07:30:08

回答

1

this使用(具有多行标志):

^(?!\s*[0-9]{2}\:[0-9]{2})\s*(?<captured>.+)$ 
1

所以..你想要任何行不是以数字开头?您的原始问题的标准不甚清楚。

你可以尝试:

^ *(?![0-9 ])(.+?) *$ 

含义,“行,后跟空间的开始,接着是参选是一个数字或空格,空格结束”。

+0

任何不以##开头的行:##(空格) – luis 2011-12-15 07:15:41

0

尝试此,我用另外RegexOptions.IgnorePatternWhitespace允许可读正则表达式和在正则表达式的评论,以及。

String s = @"string test hello world! 
    bitmap player player.png 
terrain(test) 
bg(sky) 
label(asdasd,sd, sd,ad,adsad, ds){sdds} 
00:30 test(asda,asdad,adsd)asdad{asd} 
    02:30 test(asda,asdad,adsd)asdad 
00:40 test(asda,asdad,adsd)asdad"; 

MatchCollection result = Regex.Matches 
    (s, @"^     # Match the start of the row (because of the Multiline option) 
      ?!\s*\d{2}:\d{2}) # Row should not start with \d{2}:\d{2} 
      \s*(.*)   # Match the row 
      $"     // Till the end of the row (because of the Multiline option) 
      ,RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); 

foreach (Match item in result) { 
    Console.WriteLine(item.Groups[1]); 
} 
Console.ReadLine();