需要有关简单正则表达式的帮助 [英] Need help with simple regular expression

查看:72
本文介绍了需要有关简单正则表达式的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网页包含这样的字符串:
< a href =''someurl.html''>< b>需要捕获此文本</b></a>在``.html''>< b>''和``</b></a>''
之间
请帮忙.

A web page contains strings like this:
<a href=''someurl.html''><b>need to capture this text</b></a> between ''.html''><b>'' and ''</b></a>''

Please, help.

推荐答案

诀窍是非贪婪的评估:(.*?)

The trick is non-greedy evaluation: (.*?)

class Program
{
    static void Main(string[] args)
    {
        string strInput = @"<a href='someurl.html'><b>need to capture this text</b></a>between '.html'><b>' and '</b></a>";
        var objMatch = Regex.Match(strInput, @"<a\s+href=[\s\S]*?><b>([\s\S]*?)</b></a>");
        if (objMatch.Success)
        {
            Console.WriteLine("Match: {0}", objMatch.Groups[1].Value);
        }
    }
}



干杯

安迪



Cheers

Andi


这篇关于需要有关简单正则表达式的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆