如何让RegEx区分表达?

时间:2014-10-21 16:43:07

标签: c# regex

我希望问题的标题有意义。

我不得不修改一个webscraper来添加VIEWSTATEGENERATOR。这是我用来获取VIEWSTATE的代码

var viewState = Regex.Match(
    responsedata, 
    "__VIEWSTATE.+?value=\"(.+?)\"",
    RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].ToString();

这对于抓取所有记录都很好,但是现在因为我想要改进scrape函数,我注意到还有一个VIEWSTATEGENERATOR字段。

我不知道如何让Regex区分这两者。我需要仍然获得Vi​​ewState,现在是VIEWSTATEGENERATOR。 我对RegEx的经验有限,但我知道通过查看代码,它可以区分两者,现在我从来没有得到ViewState,只有VIEWSTATEGENERATOR值。

样品 This is a screen shot from Fiddler2, You can see that there is VIEWSTATE and VIEWSTATEGENERATOR

这是字符串,这是我的表达式不起作用的地方,因为它看到了viewstate和viewstategenerator,我需要将它们分开。

  

manScript_HiddenField =安培; __ EVENTTARGET = P%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24btnSubmit&安培; __ EVENTARGUMENT =安培; __ LASTFOCUS =安培; LNG =烯CA&安培; __ VIEWSTATEGENERATOR = A5343185&安培; P%24lt%24ctl00 %24SearchBox%24txtWord =网站+搜索和; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24txtLastName =安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24grpGender = +&安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24ddLanguage = 08&安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24grpDocType = rdoDocTypeSpecialist&安培; p%24lt%24ctl03%24pageplaceholder%的24p% 24lt%24ctl03%24AllDoctorsSearch%24ddSpecialist = 149安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24grpStatus = rdoStatusActive&安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24ddCity =选择+ - - %3E&安培; p%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24tx tPostalCode =安培; P%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24ddHospitalCity =选择+ - %3E&安培; P%24lt%24ctl03%24pageplaceholder%的24p%24lt%24ctl03%24AllDoctorsSearch%24ddHospitalName = -1&安培; __ VIEWSTATE =%

1 个答案:

答案 0 :(得分:1)

不确定您的意思,但确保没有GENERATOR

"__VIEWSTATE(?!GENERATOR).+?value=\"(.+?)\""