我需要一个可以从以下文本中选择的正则表达式:
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 :(得分:1)
那么..你想要任何不以数字开头的行吗?你的原始问题的标准不是很清楚。
你可以尝试:
^ *(?![0-9 ])(.+?) *$
含义,“行的开头后跟空格,然后是不是数字或空格的对象,以空格结尾”。
答案 1 :(得分:1)
使用this(使用多行标记):
^(?!\s*[0-9]{2}\:[0-9]{2})\s*(?<captured>.+)$
答案 2 :(得分: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();