110,538
社区成员
发帖
与我相关
我的任务
分享
Match m = Regex.Match(yourStr, @"<title>(?<title>[\s\S]*?)</title>[\s\S]*?<curl>(?<curl>[\s\S]*?)</curl>", RegexOptions.IgnoreCase);
if(m.Success)
{
richTextBox2.Text += m.Groups["title"].Value + "\n";
richTextBox2.Text += m.Groups["curl"].Value + "\n";
}
using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;
namespace ConsoleApplication6
{
internal class Program
{
private static void Main(string[] args)
{
string str1 =
@"<title>AAAA </title>
<desc>BBBB </desc>
<surl>CCCC </surl>
<curl>DDDD </curl>";
string str2 =
@"<title>AAAA </title>
<curl>DDDD </curl>";
Regex regex = new Regex(@"(<title>(?<title>[\w\s]+)</title>)[\w</>\s\n]*(<curl>(?<curl>[\w\s]+)</curl>)");
if(regex.IsMatch(str1))
{
Console.WriteLine(regex.Match(str1).Groups["title"]);
Console.WriteLine(regex.Match(str1).Groups["curl"]);
}
if(regex.IsMatch(str2))
{
Console.WriteLine(regex.Match(str1).Groups["title"]);
Console.WriteLine(regex.Match(str1).Groups["curl"]);
}
Console.ReadLine();
}
}
}