正则表达式提取指定内容

时间:2022-04-23
本文章向大家介绍正则表达式提取指定内容,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
using System;

using System.Text.RegularExpressions;



public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {



        string pattern = @"{LINKTECH|(S[^{}]+)}";

        string Test = "{BAIDU|xxxxx|yyyy}{LINKTECH|A2004|00000|123123}{GOOGLE|ddddd|ddd}";

        Match mc = Regex.Match(Test, pattern, RegexOptions.IgnoreCase);



        foreach (Group G in mc.Groups)

        {

            Response.Write(G.Value.ToString() + "<br/>");

        }

    }



}

运行结果:

{LINKTECH|A2004|00000|123123}

A2004|00000|123123