C# 使用正则表达式从字符串中获取标题属性 string asd=“”
如何在c语言中从标题atribute中提取文本#C# 使用正则表达式从字符串中获取标题属性 string asd=“”,c#,regex,C#,Regex,如何在c语言中从标题atribute中提取文本# 然后在标题后插入另一个atribute?搜索:(?试试这个:你可能对HTMLAgilityPack答案特别感兴趣 name Regex reg=new Regex(“”)。组[1]。值 我需要替换获取标题值后的文本,如何获取标题值。谢谢advance@Alex你说的是哪个值?你能举个例子吗?我需要title属性的值,…在我的例子中,值是'name',然后不要替换它,只是把它保存在一个捕获组中,等等,我会更新我的答案。我刚刚给了你一个代码示例,你
然后在标题后插入另一个atribute?搜索:
(?试试这个:你可能对HTMLAgilityPack答案特别感兴趣
name
Regex reg=new Regex(“”)。组[1]。值
我需要替换获取标题值后的文本,如何获取标题值。谢谢advance@Alex你说的是哪个值?你能举个例子吗?我需要title属性的值,…在我的例子中,值是'name',然后不要替换它,只是把它保存在一个捕获组中,等等,我会更新我的答案。我刚刚给了你一个代码示例,你知道吗可以基于regexparses“]*?title=”([^“]*?”[^>]*?>“-无成对的结束括号)。
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// This is the input string we are replacing parts from.
string input = "<area href='#' title='name' shape='poly' coords='38,23,242'/>";
// Use Regex.Replace to replace the pattern in the input.
// ... The pattern N.t indicates three letters, N, any character, and t.
string output = Regex.Replace(input, "(?<=title=')[^']+", "something");
// Write the output.
Console.WriteLine(input);
Console.WriteLine(output);
}
}
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
// First we see the input string.
string input = "<area href='#' title='name' shape='poly' coords='38,23,242'/>";
// Here we call Regex.Match.
Match match = Regex.Match(input, @"title='(\w+)'",
RegexOptions.IgnoreCase);
// Here we check the Match instance.
if (match.Success)
{
// Finally, we get the Group value and display it.
string key = match.Groups[1].Value;
Console.WriteLine(key);
}
}
}
name
Regex reg = new Regex("<a[^>]*?title=\"([^\"]*?\"[^>]*?>");
reg.Match("<a href=\"#\" title=\"Hello\">Howdy</a>").Groups[1].Value