Removing unwanted text outside <>

前端 未结 2 1042
忘了有多久
忘了有多久 2021-01-29 06:48

I want to remove all text except the text within <>\'s from a textbox.

2条回答
  •  萌比男神i
    2021-01-29 07:18

    Try this

    var strText = "asdasdsdsdf sdfsfsdf";
    var pattern = new Regex(@"\<(?(.+?))\>");
    var matches = pattern.Matches(strText);
    foreach (Match match in matches)
    {
        Console.WriteLine("Data: " + match.Groups["data"]);
    } 
    //Output:
    //Data: data1
    //Data: data2
    

提交回复
热议问题