本文介绍了意外为空的匹配组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用正则表达式来抓取网页的内容.我对另一张桌子使用了类似的方法,效果很好;但我有这个问题

.Giocatore_ammonito = Regex.Match(Content, "<td class=""player large-link""\s*>(.+?)</td>").Groups(1).ToString

Content 来自http://it.soccerway.com/a/block_competition_playerstats?block_id=page_competition_1_block_competition_playerstats_9&callback_params=%7B%22round_id%22%3A%2227139%22%2C%22view%22%3A%222%22%7D&%22%22%7D&%22%22%20%2%22%7D&%A%7D.

Groups(1).ToString 返回空白结果,但我不明白为什么.

我缺少的正则表达式有什么问题?

为了完整性,这里是 Content 的内联值:

{"commands":[{"name":"updateContainer","parameters":{"content":"<div class=\"container-full\"><div class=\ 块clearfix block_competition_playerstats_diciplinary-包装\" ID = \ page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1-包装\" >< DIV类= \ 内容\" >< DIV ID = \ page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_pagination \" 类= \分页匹配分页clearfix\"><div class=\"nav_description\"><a rel=\"previous\" class=\"previous disabled\" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_previous\;la\/a><a rel=\"next\" class=\"next\" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_next\">successiva &raquo;<\/a\/div;/div>

<th class=\"number red-cards\"><img src=\"http:\/\/s1.swimg.net\/gsmf\/520\/img\/events\/RC.png\" width=\"13\" height=\"13\" alt=\"Cartellino rosso\" title=\"Cartellino rosso\" \/>R.M\u00e1rquez<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/hellas-verona-fc\/1277\/\" title=\"Hellas Verona\">Verona<\/a><\/td><td class=\"number Yellow-cards\">5<\/td><;td class=\"number red-cards\">2<\/td><td class=\"number points\">11<\/td><\/tr><tr class=\"even\" data-people_id=\"13870\"><td class=\"player large-link\"><a href=\"\/players\/facundo-sebastian-roncaglia\/13870\/\"class=\"flag_16 left_16 argentina_16_left\"> F.龙卡利亚<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"热那亚\">热那亚<\/a><\/td><td class=\"黄牌号码\">5<\/td><td class=\"号码红牌\">211A.Acquah<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/parma-fc\/1243\/\" title=\"Parma\">Parma7110D.博内拉<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ac-milan\/1240\/\" title=\"米兰\">米兰<\/a><\/td><d class=\"黄牌号码\">3<\/td><td class=\"红牌号码\">29 F.Peluso<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/us-sassuolo-calcio\/5681\/\" title=\"Sassuolo\">Sassuolo<\/a><\/td><td class=\"number Yellow-cards\">6<\/td><td class=\"红牌数\">19S.Sturaro<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"热那亚\">热那亚<\/a><\/td><td class=\"黄牌号码\">5<\/td><td class=\"号码红牌\">1<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"even\"data-people_id=\"4295\"><td class=\"player large-link\"><a href=\"\/players\/luca-cigarini\/4295\/\" class=\"flag_16 left_16 italy_16_left\"> L.Cigarini<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/atalanta-bergamo\/1255\/\" title=\"亚特兰大\">亚特兰大<\/a><\/td><td class=\"number Yellow-cards\">5<\/td><td class=\"号码红牌\">18D.Berardi<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/us-sassuolo-calcio\/5681\/\" title=\"Sassuolo\">Sassuolo<\/a><\/td><td class=\"number Yellow-cards\">5<\/td><td class=\"红牌数\">18N.德容<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ac-milan\/1240\/\" title=\"米兰\">米兰<\/a><\/td><td class=\"黄牌号码\">8<\/td><td class=\"红牌数\">08S.Padoin<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/juventus-fc\/1242\/\" title=\"尤文图斯\">尤文图斯<\/a><\/td><td class=\"黄牌号码\">1<\/td><td class=\"红牌号码\">27 I.Radovanovi\u0107V.Ibarbo<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/cagliari-calcio\/1256\/\" title=\"卡利亚里\">卡利亚里<\/a><\/td><td class=\"number Yellow-cards\">4<\/td><td class=\"号码红牌\">17 D.德罗西<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/as-roma\/1241\/\" title=\"Roma\">Roma417 K.库利巴利<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ssc-napoli\/1270\/\" title=\"那不勒斯\">那不勒斯<\/a><\/td><td class=\"黄牌号码\">4<\/td><td class=\红牌号码">1<\/td><td class=\number points\">7<\/td><\/tr><\/tbody><tfoot><tr><td colspan=\"5\">abbiamo assegnato punti per ciascun cartellino giallo (1 punto) e rosso (3 punti).<\/td><\/tr><\/tfoot><\/table><script type=\"text\/javascript\" charset=\"utf-8\">(function(){var table = $('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table');Popupizer.setup(table.select('tbody td[class*=\"yellow-cards\"]]', { column: 'yellow_cards' });Popupizer.setup(table.select('tbody td[class*=\"red-cards\"]'), 'player_events', { column: 'red_cards' });new PopupManager(table);})();\n<\/script><\/div><\/div>\n<\/div>\n<script type=\"text\/javascript\" charset=\"utf-8\">(function() {var block = new PaginatedBlock('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1', 'block_competition_playerstats_diciplinary', {\"page:\"\"0round_id\":27139,\"season_id\":0});block.registerForCallbacks();block.setAttribute('has_previous_page', false);block.setAttribute('has_next_page', true);TimestampFormatter.format('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1');})();\n<\/script><\/div>"name"}"updateCallbackParams","parameters":{"params":{"round_id":"27139","view":"2"}}}],"timestamp":"Sun, 04 Jan 2015 20:52:10 +0100"}

概述

继续@Rawing 开始发表评论的方向,正则表达式需要考虑的内容中存在反斜杠转义问题.

试试这个...

.Giocatore_ammonito = Regex.Match(Content, "<td class=\\""player large-link\\""\s*>(.+?)<\\/td>").Groups(1).ToString' ^^ ^^ ^^

...考虑到 class 属性值的双引号前面的反斜杠 td 结束标签.

另外,您可能希望清除反斜杠转义,否则将保留在匹配组值中.

演示代码

这里是 VB.NET 代码,显示了1)更新后的正则表达式如何处理您的内容以及2)如何有选择地清除从匹配组中转义的残留反斜杠值:

' 注意:从问题中提供的 URL 返回的内容Dim Content As String = "{""commands"":[{""name"":""updateContainer"",""parameters"":{""content"":""<div class=\""容器满\""><div class=\""block clearfix block_competition_playerstats_diciplinary-wrapper\"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1-wrapper\"">"<dciplinary_1-wrapper\"">"<"<"<;<div id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_pagination\"" class=\""分页匹配-分页清除修复\""><div class=\""nav_description\"">上一个\"" class=\""上一个禁用\"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_previous\"">&laquo; precedente<\/a><a"\"="""next \"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_next\"">successiva &raquo;<\/a><\/div><\/div>< DIV类= \ " block_competition_playerstats_diciplinary实时内容clearfix \ " ID = \ " page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1 \ " ><表类= \ " playerstats表\ " ID = \ " page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table \ " 数据-round_id=\""27139\"" data-season_id=\""0\""> R.M\u00e1rquez<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/hellas-verona-fc\/1277\/\"" title=\""Hellas Verona\"">Verona<\/a><\/td><td class=\""黄牌号码\"">5<\/td><td class=\""红牌号码\"">2<\/td><td class=\""号码点\"">11<\/td><\/tr><tr class=\""even\"" data-people_id=\""13870\""><td class=\""玩家大链接\""><;a href=\""\/players\/facundo-sebastian-roncaglia\/13870\/\"" class=\""flag_16 left_16 argentina_16_left\""> F.龙卡利亚<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/genoa-cfc\/1276\/\"" title=\""Genoa\"">Genoa<\/a><\/td><td class=\""数字黄牌\"">5<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">11<\/td><\/tr><tr class=\""odd\"" data-people_id=\""148164\""><td class=\""player large-link\""><a href=\""\/players\/afriyie-acquah\/148164\/\"" class=\""flag_16 left_16 ghana_16_left\"">A.Acquah<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/parma-fc\/1243\/\""title=\""Parma\"">Parma<\/a><\/td><td class=\""编号黄牌\"">7<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">10<\/td><\/tr><tr class=\""even\"" data-people_id=\""3991\""><td class=\""player large-link\""><a href=\""\/players\/daniele-bonera\/3991\/\"" class=\""flag_16 left_16 italy_16_left\"">D.博内拉<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ac-milan\/1240\/\"" title=\""米兰\"">米兰3 F.Peluso<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/us-sassuolo-calcio\/5681\/\"" title=\""Sassuolo\"">Sassuolo<\/a><\/td><td class=\""黄牌号码\"">6<\/td><td class=\""红牌号码\"">1<\/td><td class=\""number points\"">9<\/td><\/tr><tr class=\""even\"" data-people_id=\""4473\""><td class=\""player large-link\""><a href=\""\/players\/dal-belo-dias-da-silva\/4473\/\"" class=\""flag_16 left_16 brazil_16_left\"">Felipe<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/parma-fc\/1243\/\"" title=\""帕尔马\"">帕尔马<\/a><\/td><d class=\""number 黄牌\"">2<\/td><td class=\""number红牌\"">28 S.Sturaro<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/genoa-cfc\/1276\/\"" title=\""Genoa\"">Genoa<\/a><\/td><td class=\""数字黄牌\"">5<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""even\"" data-people_id=\""4295\""><td class=\""player large-link\""><a href=\""\/players\/luca-cigarini\/4295\/\"" class=\""flag_16 left_16 italy_16_left\""> L.Cigarini<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/atalanta-bergamo\/1255\/\""title=\""亚特兰大\"">亚特兰大5D.Berardi<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/us-sassuolo-calcio\/5681\/\"" title=\""Sassuolo\"">Sassuolo5N.德容<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ac-milan\/1240\/\"" title=\""米兰\"">米兰<\/a><\/td><td class=\""黄牌号码\"">8<\/td><td class=\""number red-cards\"">0<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""odd\"" data-people_id=\""17855\""><td class=\""player large-link\""><a href=\""\/players\/simone-padoin\/17855\/\"" class=\""flag_16 left_16 italy_16_left\"">S.Padoin<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/juventus-fc\/1242\/\"" title=\"""尤文图斯\"">尤文图斯<\/a><\/td><td class=\""黄牌号码\"">1<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">7<\/td><\/tr><tr class=\""even\"" data-people_id=\""61429\""><td class=\""player large-link\""><a href=\""\/players\/ivan-radovanovic\/61429\/\"" class=\""flag_16 left_16 serbia_16_left\""> I.Radovanovi\u0107V.Ibarbo<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/cagliari-calcio\/1256\/\"" title=\""卡利亚里\"">卡利亚里4D.德罗西<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/as-roma\/1241\/\"" title=\""Roma\"">Roma4K.库利巴利<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ssc-napoli\/1270\/\"" title=\""那不勒斯\"">那不勒斯<\/a><\/td><td class=\""黄牌号码\"">4<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">7<\/td><\/tr><\/tbody><tfoot><tr><td colspan=\""5\"">abbiamo assegnato punti per ciascun cartellino giallo (1 punto) e rosso (3 punti).<\/td><\/tr><\/tfoot><\/table><script type=\""text\/javascript\"" charset=\""utf-8\"">(function(){var table = $('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table');Popupizer.setup(table.select('tbody td[class*=\"""yellow-card)]'), 'player_events', { column: 'yellow_cards' });Popupizer.setup(table.select('tbody td[class*=\""red-cards\""]'), 'player_events', {column: 'red_cards' });new PopupManager(table);})();\n<\/script><\/div><\/div>\n<\/div>\n<脚本类型=\""text\/javascript\"" charset=\""utf-8\"">(function() {var block = new PaginatedBlock('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1', 'block_competition_playerstats,"\diciplin":0,\""per_page\"":15,\""round_id\"":27139,\""season_id\"":0});block.registerForCallbacks();block.setAttribute('has_previous_page', false);block.setAttribute('has_next_page', true);TimestampFormatter.format('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1');})();\n<}\/script><"\/,{""name"":""updateCallbackParams"",""参数"":{""params"":{""round_id"":""27139"",""view"":""2""}}}],""timestamp"":""2015 年 1 月 4 日星期日 20:52:10 +0100""}"' FORNOW:将第一个匹配组的值输出到控制台,而不是将其分配给 .Giocatore_ammonito.Dim FirstMatchGroup As String = Regex.Match(Content, "<td class=\\""player large-link\\""\s*>(.+?)<\\/td>").Groups(1).ToStringConsole.WriteLine("第一个匹配组的值")Console.WriteLine("-----------------------")Console.WriteLine(FirstMatchGroup & Environment.NewLine)'.Giocatore_ammonito = Regex.Match(Content, "(.+?)").Groups(1).ToString' 注意:我认为您真正想要的是第一个匹配组值的擦洗版本(即没有所有反斜杠转义).Dim ScrubbedFirstMatchGroup As String = FirstMatchGroup.Replace("\""", """").Replace("\/", "/")Console.WriteLine("第一个匹配组的值(已删除)")Console.WriteLine("---------------------------------")Console.WriteLine(ScrubbedFirstMatchGroup)

输出如下:

第一个匹配组的值-----------------------<a href=\"\/players\/rafael-marquez-alvarez\/416\/\" class=\"flag_16 left_16 mexico_16_left\">R.M\u00e1rquez<\/a>第一个比赛组的价值(擦洗)----------------------------------<a href="/players/rafael-marquez-alvarez/416/" class="flag_16 left_16 mexico_16_left">R.M\u00e1rquez</a>

I am using a regex to grab content for a web page. I use a similar approach for another table, and that is working well; but I have a problem with this

.Giocatore_ammonito = Regex.Match(Content, "<td class=""player large-link""\s*>(.+?)</td>").Groups(1).ToString

where Content comes from http://it.soccerway.com/a/block_competition_playerstats?block_id=page_competition_1_block_competition_playerstats_9&callback_params=%7B%22round_id%22%3A%2227139%22%2C%22view%22%3A%222%22%7D&action=changeView&params=%7B%22view%22%3A2%7D.

Groups(1).ToString returns a blank result, but I do not understand why.

What is wrong with the regex that I am missing?

For completeness, here is Content's value inline:

{"commands":[{"name":"updateContainer","parameters":{"content":"<div class=\"container-full\"><div class=\"block  clearfix block_competition_playerstats_diciplinary-wrapper\" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1-wrapper\"><div class=\"content  \"><div id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_pagination\" class=\"pagination match-pagination clearfix\"><div class=\"nav_description\"><a rel=\"previous\" class=\"previous disabled\" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_previous\">&laquo; precedente<\/a><a rel=\"next\" class=\"next \" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_next\">successiva &raquo;<\/a><\/div><\/div><div class=\"block_competition_playerstats_diciplinary real-content clearfix \" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1\"><table class=\"playerstats table\" id=\"page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table\" data-round_id=\"27139\" data-season_id=\"0\"><thead><tr class=\"sub-head\"><th class=\"player\">Giocatore<\/th><th class=\"team\">Squadra<\/th><th class=\"number yellow-cards\"><img src=\"http:\/\/s1.swimg.net\/gsmf\/520\/img\/events\/YC.png\" width=\"13\" height=\"13\" alt=\"Cartellino giallo\" title=\"Cartellino giallo\" \/><\/th><th class=\"number red-cards\"><img src=\"http:\/\/s1.swimg.net\/gsmf\/520\/img\/events\/RC.png\" width=\"13\" height=\"13\" alt=\"Cartellino rosso\" title=\"Cartellino rosso\" \/><\/th><th class=\"number points\"><acronym title=\"Punti\">Pts<\/acronym><\/th><\/tr><\/thead><tbody><tr class=\"odd\" data-people_id=\"416\"><td class=\"player large-link\"><a href=\"\/players\/rafael-marquez-alvarez\/416\/\" class=\"flag_16 left_16 mexico_16_left\">R. M\u00e1rquez<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/hellas-verona-fc\/1277\/\" title=\"Hellas Verona\">Verona<\/a><\/td><td class=\"number yellow-cards\">5<\/td><td class=\"number red-cards\">2<\/td><td class=\"number points\">11<\/td><\/tr><tr class=\"even\" data-people_id=\"13870\"><td class=\"player large-link\"><a href=\"\/players\/facundo-sebastian-roncaglia\/13870\/\" class=\"flag_16 left_16 argentina_16_left\">F. Roncaglia<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"Genoa\">Genoa<\/a><\/td><td class=\"number yellow-cards\">5<\/td><td class=\"number red-cards\">2<\/td><td class=\"number points\">11<\/td><\/tr><tr class=\"odd\" data-people_id=\"148164\"><td class=\"player large-link\"><a href=\"\/players\/afriyie-acquah\/148164\/\" class=\"flag_16 left_16 ghana_16_left\">A. Acquah<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/parma-fc\/1243\/\" title=\"Parma\">Parma<\/a><\/td><td class=\"number yellow-cards\">7<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">10<\/td><\/tr><tr class=\"even\" data-people_id=\"3991\"><td class=\"player large-link\"><a href=\"\/players\/daniele-bonera\/3991\/\" class=\"flag_16 left_16 italy_16_left\">D. Bonera<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ac-milan\/1240\/\" title=\"Milan\">Milan<\/a><\/td><td class=\"number yellow-cards\">3<\/td><td class=\"number red-cards\">2<\/td><td class=\"number points\">9<\/td><\/tr><tr class=\"odd\" data-people_id=\"18275\"><td class=\"player large-link\"><a href=\"\/players\/federico-peluso\/18275\/\" class=\"flag_16 left_16 italy_16_left\">F. Peluso<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/us-sassuolo-calcio\/5681\/\" title=\"Sassuolo\">Sassuolo<\/a><\/td><td class=\"number yellow-cards\">6<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">9<\/td><\/tr><tr class=\"even\" data-people_id=\"4473\"><td class=\"player large-link\"><a href=\"\/players\/dal-belo-dias-da-silva\/4473\/\" class=\"flag_16 left_16 brazil_16_left\">Felipe<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/parma-fc\/1243\/\" title=\"Parma\">Parma<\/a><\/td><td class=\"number yellow-cards\">2<\/td><td class=\"number red-cards\">2<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"odd\" data-people_id=\"178336\"><td class=\"player large-link\"><a href=\"\/players\/stefano-sturaro\/178336\/\" class=\"flag_16 left_16 italy_16_left\">S. Sturaro<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"Genoa\">Genoa<\/a><\/td><td class=\"number yellow-cards\">5<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"even\" data-people_id=\"4295\"><td class=\"player large-link\"><a href=\"\/players\/luca-cigarini\/4295\/\" class=\"flag_16 left_16 italy_16_left\">L. Cigarini<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/atalanta-bergamo\/1255\/\" title=\"Atalanta\">Atalanta<\/a><\/td><td class=\"number yellow-cards\">5<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"odd\" data-people_id=\"246415\"><td class=\"player large-link\"><a href=\"\/players\/domenico-berardi\/246415\/\" class=\"flag_16 left_16 italy_16_left\">D. Berardi<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/us-sassuolo-calcio\/5681\/\" title=\"Sassuolo\">Sassuolo<\/a><\/td><td class=\"number yellow-cards\">5<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"even\" data-people_id=\"2006\"><td class=\"player large-link\"><a href=\"\/players\/nigel-de-jong\/2006\/\" class=\"flag_16 left_16 netherlands_16_left\">N. de Jong<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ac-milan\/1240\/\" title=\"Milan\">Milan<\/a><\/td><td class=\"number yellow-cards\">8<\/td><td class=\"number red-cards\">0<\/td><td class=\"number points\">8<\/td><\/tr><tr class=\"odd\" data-people_id=\"17855\"><td class=\"player large-link\"><a href=\"\/players\/simone-padoin\/17855\/\" class=\"flag_16 left_16 italy_16_left\">S. Padoin<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/juventus-fc\/1242\/\" title=\"Juventus\">Juventus<\/a><\/td><td class=\"number yellow-cards\">1<\/td><td class=\"number red-cards\">2<\/td><td class=\"number points\">7<\/td><\/tr><tr class=\"even\" data-people_id=\"61429\"><td class=\"player large-link\"><a href=\"\/players\/ivan-radovanovic\/61429\/\" class=\"flag_16 left_16 serbia_16_left\">I. Radovanovi\u0107<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ac-chievo-verona\/1248\/\" title=\"Chievo Verona\">Chievo<\/a><\/td><td class=\"number yellow-cards\">4<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">7<\/td><\/tr><tr class=\"odd\" data-people_id=\"71325\"><td class=\"player large-link\"><a href=\"\/players\/segundo-victor-ibarbo-guerrero\/71325\/\" class=\"flag_16 left_16 colombia_16_left\">V. Ibarbo<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/cagliari-calcio\/1256\/\" title=\"Cagliari\">Cagliari<\/a><\/td><td class=\"number yellow-cards\">4<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">7<\/td><\/tr><tr class=\"even\" data-people_id=\"71\"><td class=\"player large-link\"><a href=\"\/players\/daniele-de-rossi\/71\/\" class=\"flag_16 left_16 italy_16_left\">D. De Rossi<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/as-roma\/1241\/\" title=\"Roma\">Roma<\/a><\/td><td class=\"number yellow-cards\">4<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">7<\/td><\/tr><tr class=\"odd\" data-people_id=\"139596\"><td class=\"player large-link\"><a href=\"\/players\/kalidou-koulibaly\/139596\/\" class=\"flag_16 left_16 france_16_left\">K. Koulibaly<\/a><\/td><td class=\"team large-link\"><a href=\"\/teams\/italy\/ssc-napoli\/1270\/\" title=\"Napoli\">Napoli<\/a><\/td><td class=\"number yellow-cards\">4<\/td><td class=\"number red-cards\">1<\/td><td class=\"number points\">7<\/td><\/tr><\/tbody><tfoot><tr><td colspan=\"5\">abbiamo assegnato punti per ciascun cartellino giallo (1 punto) e rosso (3 punti). Da notare che non rappresentano alcuna classifica ufficiale.<\/td><\/tr><\/tfoot><\/table><script type=\"text\/javascript\" charset=\"utf-8\">(function(){var table = $('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table');Popupizer.setup(table.select('tbody td[class*=\"yellow-cards\"]'), 'player_events', { column: 'yellow_cards' });Popupizer.setup(table.select('tbody td[class*=\"red-cards\"]'), 'player_events', { column: 'red_cards' });new PopupManager(table);})();\n<\/script><\/div><\/div>\n<\/div>\n<script type=\"text\/javascript\" charset=\"utf-8\">(function() {var block = new PaginatedBlock('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1', 'block_competition_playerstats_diciplinary', {\"page\":0,\"per_page\":15,\"round_id\":27139,\"season_id\":0});block.registerForCallbacks();block.setAttribute('has_previous_page', false);block.setAttribute('has_next_page', true);TimestampFormatter.format('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1');})();\n<\/script><\/div>\n"}},{"name":"updateCallbackParams","parameters":{"params":{"round_id":"27139","view":"2"}}}],"timestamp":"Sun, 04 Jan 2015 20:52:10 +0100"}
解决方案

Overview

Continuing in the direction that @Rawing started going with his comment, there are backslash-escaping issues in the content for which the regex needs to account.

Try this instead...

.Giocatore_ammonito = Regex.Match(Content, "<td class=\\""player large-link\\""\s*>(.+?)<\\/td>").Groups(1).ToString
'                                                     ^^                   ^^            ^^

...to account for backslashes preceding the double quotes around the class attributes' values and the backslashes preceding the forward slashes in the td closing tags.

Also, you may wish to scrub the backslash escaping that will otherwise remain in the match-group value(s).

Demo Code

Here is VB.NET code that shows 1) how the updated regex works with your content and 2) how to optionally scrub lingering backslash escaping from the match-group value(s):

' NOTE: content returned from the URL provided in the question
Dim Content As String = "{""commands"":[{""name"":""updateContainer"",""parameters"":{""content"":""<div class=\""container-full\""><div class=\""block  clearfix block_competition_playerstats_diciplinary-wrapper\"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1-wrapper\""><div class=\""content  \""><div id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_pagination\"" class=\""pagination match-pagination clearfix\""><div class=\""nav_description\""><a rel=\""previous\"" class=\""previous disabled\"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_previous\"">&laquo; precedente<\/a><a rel=\""next\"" class=\""next \"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_next\"">successiva &raquo;<\/a><\/div><\/div><div class=\""block_competition_playerstats_diciplinary real-content clearfix \"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1\""><table class=\""playerstats table\"" id=\""page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table\"" data-round_id=\""27139\"" data-season_id=\""0\""><thead><tr class=\""sub-head\""><th class=\""player\"">Giocatore<\/th><th class=\""team\"">Squadra<\/th><th class=\""number yellow-cards\""><img src=\""http:\/\/s1.swimg.net\/gsmf\/520\/img\/events\/YC.png\"" width=\""13\"" height=\""13\"" alt=\""Cartellino giallo\"" title=\""Cartellino giallo\"" \/><\/th><th class=\""number red-cards\""><img src=\""http:\/\/s1.swimg.net\/gsmf\/520\/img\/events\/RC.png\"" width=\""13\"" height=\""13\"" alt=\""Cartellino rosso\"" title=\""Cartellino rosso\"" \/><\/th><th class=\""number points\""><acronym title=\""Punti\"">Pts<\/acronym><\/th><\/tr><\/thead><tbody><tr class=\""odd\"" data-people_id=\""416\""><td class=\""player large-link\""><a href=\""\/players\/rafael-marquez-alvarez\/416\/\"" class=\""flag_16 left_16 mexico_16_left\"">R. M\u00e1rquez<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/hellas-verona-fc\/1277\/\"" title=\""Hellas Verona\"">Verona<\/a><\/td><td class=\""number yellow-cards\"">5<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">11<\/td><\/tr><tr class=\""even\"" data-people_id=\""13870\""><td class=\""player large-link\""><a href=\""\/players\/facundo-sebastian-roncaglia\/13870\/\"" class=\""flag_16 left_16 argentina_16_left\"">F. Roncaglia<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/genoa-cfc\/1276\/\"" title=\""Genoa\"">Genoa<\/a><\/td><td class=\""number yellow-cards\"">5<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">11<\/td><\/tr><tr class=\""odd\"" data-people_id=\""148164\""><td class=\""player large-link\""><a href=\""\/players\/afriyie-acquah\/148164\/\"" class=\""flag_16 left_16 ghana_16_left\"">A. Acquah<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/parma-fc\/1243\/\"" title=\""Parma\"">Parma<\/a><\/td><td class=\""number yellow-cards\"">7<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">10<\/td><\/tr><tr class=\""even\"" data-people_id=\""3991\""><td class=\""player large-link\""><a href=\""\/players\/daniele-bonera\/3991\/\"" class=\""flag_16 left_16 italy_16_left\"">D. Bonera<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ac-milan\/1240\/\"" title=\""Milan\"">Milan<\/a><\/td><td class=\""number yellow-cards\"">3<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">9<\/td><\/tr><tr class=\""odd\"" data-people_id=\""18275\""><td class=\""player large-link\""><a href=\""\/players\/federico-peluso\/18275\/\"" class=\""flag_16 left_16 italy_16_left\"">F. Peluso<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/us-sassuolo-calcio\/5681\/\"" title=\""Sassuolo\"">Sassuolo<\/a><\/td><td class=\""number yellow-cards\"">6<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">9<\/td><\/tr><tr class=\""even\"" data-people_id=\""4473\""><td class=\""player large-link\""><a href=\""\/players\/dal-belo-dias-da-silva\/4473\/\"" class=\""flag_16 left_16 brazil_16_left\"">Felipe<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/parma-fc\/1243\/\"" title=\""Parma\"">Parma<\/a><\/td><td class=\""number yellow-cards\"">2<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""odd\"" data-people_id=\""178336\""><td class=\""player large-link\""><a href=\""\/players\/stefano-sturaro\/178336\/\"" class=\""flag_16 left_16 italy_16_left\"">S. Sturaro<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/genoa-cfc\/1276\/\"" title=\""Genoa\"">Genoa<\/a><\/td><td class=\""number yellow-cards\"">5<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""even\"" data-people_id=\""4295\""><td class=\""player large-link\""><a href=\""\/players\/luca-cigarini\/4295\/\"" class=\""flag_16 left_16 italy_16_left\"">L. Cigarini<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/atalanta-bergamo\/1255\/\"" title=\""Atalanta\"">Atalanta<\/a><\/td><td class=\""number yellow-cards\"">5<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""odd\"" data-people_id=\""246415\""><td class=\""player large-link\""><a href=\""\/players\/domenico-berardi\/246415\/\"" class=\""flag_16 left_16 italy_16_left\"">D. Berardi<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/us-sassuolo-calcio\/5681\/\"" title=\""Sassuolo\"">Sassuolo<\/a><\/td><td class=\""number yellow-cards\"">5<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""even\"" data-people_id=\""2006\""><td class=\""player large-link\""><a href=\""\/players\/nigel-de-jong\/2006\/\"" class=\""flag_16 left_16 netherlands_16_left\"">N. de Jong<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ac-milan\/1240\/\"" title=\""Milan\"">Milan<\/a><\/td><td class=\""number yellow-cards\"">8<\/td><td class=\""number red-cards\"">0<\/td><td class=\""number points\"">8<\/td><\/tr><tr class=\""odd\"" data-people_id=\""17855\""><td class=\""player large-link\""><a href=\""\/players\/simone-padoin\/17855\/\"" class=\""flag_16 left_16 italy_16_left\"">S. Padoin<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/juventus-fc\/1242\/\"" title=\""Juventus\"">Juventus<\/a><\/td><td class=\""number yellow-cards\"">1<\/td><td class=\""number red-cards\"">2<\/td><td class=\""number points\"">7<\/td><\/tr><tr class=\""even\"" data-people_id=\""61429\""><td class=\""player large-link\""><a href=\""\/players\/ivan-radovanovic\/61429\/\"" class=\""flag_16 left_16 serbia_16_left\"">I. Radovanovi\u0107<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ac-chievo-verona\/1248\/\"" title=\""Chievo Verona\"">Chievo<\/a><\/td><td class=\""number yellow-cards\"">4<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">7<\/td><\/tr><tr class=\""odd\"" data-people_id=\""71325\""><td class=\""player large-link\""><a href=\""\/players\/segundo-victor-ibarbo-guerrero\/71325\/\"" class=\""flag_16 left_16 colombia_16_left\"">V. Ibarbo<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/cagliari-calcio\/1256\/\"" title=\""Cagliari\"">Cagliari<\/a><\/td><td class=\""number yellow-cards\"">4<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">7<\/td><\/tr><tr class=\""even\"" data-people_id=\""71\""><td class=\""player large-link\""><a href=\""\/players\/daniele-de-rossi\/71\/\"" class=\""flag_16 left_16 italy_16_left\"">D. De Rossi<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/as-roma\/1241\/\"" title=\""Roma\"">Roma<\/a><\/td><td class=\""number yellow-cards\"">4<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">7<\/td><\/tr><tr class=\""odd\"" data-people_id=\""139596\""><td class=\""player large-link\""><a href=\""\/players\/kalidou-koulibaly\/139596\/\"" class=\""flag_16 left_16 france_16_left\"">K. Koulibaly<\/a><\/td><td class=\""team large-link\""><a href=\""\/teams\/italy\/ssc-napoli\/1270\/\"" title=\""Napoli\"">Napoli<\/a><\/td><td class=\""number yellow-cards\"">4<\/td><td class=\""number red-cards\"">1<\/td><td class=\""number points\"">7<\/td><\/tr><\/tbody><tfoot><tr><td colspan=\""5\"">abbiamo assegnato punti per ciascun cartellino giallo (1 punto) e rosso (3 punti). Da notare che non rappresentano alcuna classifica ufficiale.<\/td><\/tr><\/tfoot><\/table><script type=\""text\/javascript\"" charset=\""utf-8\"">(function(){var table = $('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1_table');Popupizer.setup(table.select('tbody td[class*=\""yellow-cards\""]'), 'player_events', { column: 'yellow_cards' });Popupizer.setup(table.select('tbody td[class*=\""red-cards\""]'), 'player_events', { column: 'red_cards' });new PopupManager(table);})();\n<\/script><\/div><\/div>\n<\/div>\n<script type=\""text\/javascript\"" charset=\""utf-8\"">(function() {var block = new PaginatedBlock('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1', 'block_competition_playerstats_diciplinary', {\""page\"":0,\""per_page\"":15,\""round_id\"":27139,\""season_id\"":0});block.registerForCallbacks();block.setAttribute('has_previous_page', false);block.setAttribute('has_next_page', true);TimestampFormatter.format('page_competition_1_block_competition_playerstats_9_block_competition_playerstats_diciplinary_1');})();\n<\/script><\/div>\n""}},{""name"":""updateCallbackParams"",""parameters"":{""params"":{""round_id"":""27139"",""view"":""2""}}}],""timestamp"":""Sun, 04 Jan 2015 20:52:10 +0100""}"
' FORNOW: Output the first match group's value to the console instead of assigning it to .Giocatore_ammonito.
Dim FirstMatchGroup As String = Regex.Match(Content, "<td class=\\""player large-link\\""\s*>(.+?)<\\/td>").Groups(1).ToString
Console.WriteLine("1st match group's value")
Console.WriteLine("-----------------------")
Console.WriteLine(FirstMatchGroup & Environment.NewLine)
'.Giocatore_ammonito = Regex.Match(Content, "<td class=\\""player large-link\\""\s*>(.+?)<\\/td>").Groups(1).ToString

' NOTE: What I think you really want is a scrubbed version of the first match group's value (i.e. without all the backslash escaping).
Dim ScrubbedFirstMatchGroup As String = FirstMatchGroup.Replace("\""", """").Replace("\/", "/")
Console.WriteLine("1st match group's value (scrubbed)")
Console.WriteLine("----------------------------------")
Console.WriteLine(ScrubbedFirstMatchGroup)

It outputs the following:

1st match group's value
-----------------------
<a href=\"\/players\/rafael-marquez-alvarez\/416\/\" class=\"flag_16 left_16 mexico_16_left\">R. M\u00e1rquez<\/a>

1st match group's value (scrubbed)
----------------------------------
<a href="/players/rafael-marquez-alvarez/416/" class="flag_16 left_16 mexico_16_left">R. M\u00e1rquez</a>

这篇关于意外为空的匹配组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 02:06