无法从 JMeter 中的变量中提取正则表达式

Trouble extracting regular expression out of a variable in JMeter

我在尝试从 JMeter 变量中提取正则表达式时遇到问题。

我正在生成一个 http 请求并得到以下响应:

{"Error":"OK","ErrorCode":0,"Data":[{"AppIconUrl":"http://a2.jqzfgh75x175-75.jpg","AppName":"26082014","AppProviderName":"f","BannerText":null,"BlockedSubAffiliates":["Unavailable"],"Categories":["games","kids"],"Creatives":[{"CreativeLink":"http://773gffff64ec6cffe3114cf789f9ca381c27e8a0_320x50.jpg","CreativeSize":"320x50","CreativeType":"Banner","Id":1234,"Name":"320x50.jpg"},{"CreativeLink":"http://77312bc1cfc3c281234_320x480.jpg","CreativeSize":"320x480","CreativeType":"FullScreen","Id":231,"Name":"320x480.jpg"},{"CreativeLink":"http://77312bc1cfc123452c7f_480x320.jpg","CreativeSize":"480x320","CreativeType":"FullScreen","Id":543,"Name":"480x320.jpg"},{"CreativeLink":"http://77312bc1cdgh7w33bc09e_320x480.jpg","CreativeSize":"320x480","CreativeType":"CompanionBanner","Id":9872,"Name":"Unavailable"},{"CreativeLink":"http://77312bc1cfcdgdhe555id!_320x480.mp4","CreativeSize":"320x480","CreativeType":"Video","Id":53433,"Name":"kid!_320x480.mp4"}],"DailyBudget":"Unavailable","Description":"Test app","DeviceIds":[],"IsDeviceIdMandatory":false,"MarketAppId":"com.teamlava.candy(test)","MinOsVersion":"2.3","Name":"test y","Networks":["WIFI","3G"],"OfferId":"75824","Payout":0.00001,"PayoutType":"CPM","Platforms":["Android"],"PreviewLink":"https://plndy.com","SupportedCountries":["AU","BR","CN","DE","IN","IL","CH","GB","US"],"TrackingLink":"http://clk.test.com/aff_c?tt_ls=b&offer_id=75824&aff_id=12&tt_appid=12(test)&tt_bannerid="},{"AppIconUrl":"http://a2.154qzpnbsu.175x175-75.jpg","AppName":"test26082014","AppProviderName":"y","BannerText":null,"BlockedSubAffiliates":["Unavailable"],"Categories":["games","kids"],"Creatives":[{"CreativeLink":"http://7731dfgmkl3428cf_320x50.jpg","CreativeSize":"320x50","CreativeType":"Banner","Id":98865554,"Name":"320x50.jpg"},{"CreativeLink":"http://77sdfgklsg0f_320x480.jpg","CreativeSize":"320x480","CreativeType":"FullScreen","Id":536372,"Name":"320x480.jpg"},{"CreativeLink":"http://7dfgh556a6c_480x320.jpg","CreativeSize":"480x320","CreativeType":"FullScreen","Id":985442525,"Name":"480x320.jpg"},{"CreativeLink":"http://7731grdk4_320x480.jpg","CreativeSize":"320x480","CreativeType":"CompanionBanner","Id":712,"Name":"Unavailable"},{"CreativeLink":"http://773tktkoid!_320x480.mp4","CreativeSize":"320x480","CreativeType":"Video","Id":63722,"Name":"bid!_320x480.mp4"}],"DailyBudget":"Unavailable","Description":"Test app2","DeviceIds":[],"IsDeviceIdMandatory":false,"MarketAppId":"aby(test)","MinOsVersion":"2.3","Name":"Test2 02122014","Networks":["WIFI","3G"],"OfferId":"3666","Payout":1.00000,"PayoutType":"CPC","Platforms":["Android"],"PreviewLink":"https://play.google.com/store/apps/details?id=com.teamlava.candy","SupportedCountries":["AU","BR","CA","DE","IL","GB","US"],"TrackingLink":"http://clk.taptica.com/aff_c?tt_ls=b&offer_id=3666&aff_id=12&tt_appid=12(test)&tt_bannerid="}]}

当我尝试从响应正文中提取以下正则表达式时,它工作正常:

Regular expression 1: "ErrorCode":([0-9]+),|([0-9]+)</errorCode>

Result 1: 0

Regular expression 2: {"AppIconUrl":(.+?)tt_bannerid="}|\n(.+?)\n|\n(.+?)$|(.+?)</Offer>

Result 2: "http://a2.jqzfgh75x175-75.jpg","AppName":"26082014","AppProviderName":"f","BannerText":null,"BlockedSubAffiliates":["Unavailable"],"Categories":["games","kids"],"Creatives":[{"CreativeLink":"http://773gffff64ec6cffe3114cf789f9ca381c27e8a0_320x50.jpg","CreativeSize":"320x50","CreativeType":"Banner","Id":1234,"Name":"320x50.jpg"},{"CreativeLink":"http://77312bc1cfc3c281234_320x480.jpg","CreativeSize":"320x480","CreativeType":"FullScreen","Id":231,"Name":"320x480.jpg"},{"CreativeLink":"http://77312bc1cfc123452c7f_480x320.jpg","CreativeSize":"480x320","CreativeType":"FullScreen","Id":543,"Name":"480x320.jpg"},{"CreativeLink":"http://77312bc1cdgh7w33bc09e_320x480.jpg","CreativeSize":"320x480","CreativeType":"CompanionBanner","Id":9872,"Name":"Unavailable"},{"CreativeLink":"http://77312bc1cfcdgdhe555id!_320x480.mp4","CreativeSize":"320x480","CreativeType":"Video","Id":53433,"Name":"kid!_320x480.mp4"}],"DailyBudget":"Unavailable","Description":"Test app","DeviceIds":[],"IsDeviceIdMandatory":false,"MarketAppId":"com.teamlava.candy(test)","MinOsVersion":"2.3","Name":"test y","Networks":["WIFI","3G"],"OfferId":"75824","Payout":0.00001,"PayoutType":"CPM","Platforms":["Android"],"PreviewLink":"https://plndy.com","SupportedCountries":["AU","BR","CN","DE","IN","IL","CH","GB","US"],"TrackingLink":"http://clk.test.com/aff_c?tt_ls=b&offer_id=75824&aff_id=12&tt_appid=12(test)&

现在,我试图从结果 2 中提取以下正则表达式,但由于某种原因它不起作用,我只得到默认值:

Regular expression 3: (clk.+)&

Expected Result 3: clk.test.com/aff_c?tt_ls=b&offer_id=75824&aff_id=12&tt_appid=12(test)

Result 3 (default): empty_click_uri

Regular expression 4: "Id":([0-9]+)|[id:(.+?) |([0-9]+?)</Id>

Expected Result 4: 1234

Result 4 (default): empty_creative_id

我在 https://regex101.com/ 中测试了我的正则表达式,似乎一切正常。我不明白为什么它不能在 JMeter 上工作。

感谢您的帮助。

找到它不起作用的原因。

因为 JMeter "knows" 这些是变量而不是字符串,所以不需要“$”、“{”和“}”。

正确的设置是: