好吧,我一直试图从带有反射的字符串中选择一些数据(在c#中)一段时间,基本上我想在Customer和< \ div>之间选择所有内容。但我似乎无法获得数据: 我的代码:
string text= "<div> Company = Fake Company </div><div>Customer: XXXX</div><div>Device: NY-FIL05 </div><div>Service: Device Fail:</div> "
var groups= Regex.Match(text, @"Customer: (.*\b</\div>\b")).Groups;
var auxi = groups[1].Value;
基本上我需要抓住XXXX,但我总是抓住一切或者什么都不抓
答案 0 :(得分:2)
string text = "<div> Company = Fake Company </div><div>Customer: XXXX</div><div>Device: NY-FIL05 </div><div>Service: Device Fail:</div>";
Match m = Regex.Match(text, @"(?<=Customer: ).*?(?=</div>)");
if (m.Success)
Console.WriteLine(m.Value);
说明:
(?<=Customer: ).*?(?=</div>)
答案 1 :(得分:1)
您可以尝试:
var groups= Regex.Match(text, @"Customer: ([\w ]+)", RegexOptions.IgnoreCase);
注意:强>
您错过了string text