using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string str = @"<html> <title>任何字符,无内容也要提取111</title> <html>如何提取<title>2222</title>之间的内容?"; Regex re = new Regex(@"(?i)(?<=<title>).*?(?=</title>)"); MatchCollection mc = re.Matches(str); foreach (Match item in mc) { Console.WriteLine(item.Value); }
string s = "<title>任何字符,无内容也要提取</title>"; Match m = Regex.Match(s, @"<title.*?>(.*?)</title>", RegexOptions.IgnoreCase); if (m.Groups.Count >= 2) { s = m.Groups[1].Value; } //s就是要最后的结果
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = @"<html>
<title>任何字符,无内容也要提取111</title>
<html>如何提取<title>2222</title>之间的内容?";
Regex re = new Regex(@"(?i)(?<=<title>).*?(?=</title>)");
MatchCollection mc = re.Matches(str);
foreach (Match item in mc)
{
Console.WriteLine(item.Value);
}
}
}
}
string s = "<title>任何字符,无内容也要提取</title>";
Match m = Regex.Match(s, @"<title.*?>(.*?)</title>", RegexOptions.IgnoreCase);
if (m.Groups.Count >= 2)
{
s = m.Groups[1].Value;
}
//s就是要最后的结果