基于特定条件的拆分c#字符串的正则表达式
我有这根绳子基于特定条件的拆分c#字符串的正则表达式,c#,regex,xamarin.ios,C#,Regex,Xamarin.ios,我有这根绳子 You have 6 uncategorized contacts from <an id='316268655'>SAP SE</an> 但从属性Id出现时起,我就无法解析它 有谁能帮我翻译一下语法吗?要得到你输入的第二部分,我在后面添加了代码部分,这是完整的代码 using System; using System.Collections.Generic; using System.Linq; using System.Tex
You have 6 uncategorized contacts from <an id='316268655'>SAP SE</an>
但从属性Id出现时起,我就无法解析它
有谁能帮我翻译一下语法吗?要得到你输入的第二部分,我在后面添加了代码部分,这是完整的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace PatternMatching
{
public class Program
{
public static void Main(string[] args)
{
string input = "You have 6 uncategorized contacts from <an id='316268655'>SAP SE</an>";
var parts = Regex.Split(input, @"(<an[\s\S]+?<\/an>)").Where(l => l != string.Empty).ToArray();
foreach(var a in parts)
{
Console.WriteLine(a);
break;
}
string pattern = "<an.*?>(.*?)<\\/an>";
MatchCollection matches = Regex.Matches(input, pattern);
if (matches.Count > 0)
foreach (Match m in matches)
Console.WriteLine(m.Groups[1]);
Console.ReadLine();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text.RegularExpressions;
命名空间模式匹配
{
公共课程
{
公共静态void Main(字符串[]args)
{
string input=“您有6个来自SAP SE的未分类联系人”;
var parts=Regex.Split(输入,@)(添加此答案,因为它将帮助您找到所需的确切答案(在第二部分中标记)
公共类程序
{
公共静态void Main(字符串[]args)
{
string input=“您有6个来自SAP SE的未分类联系人”;
var parts=Regex.Split(输入,@“(使用]*>)([^I对我不起作用:(在上面分成4个部分,我尝试过并工作过,但再次无法获得id outSee(请参见Split List tab)。此程序将给出第二个没有标记的输出,看起来您已经在第二部分输出中编辑了问题并添加了标记
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace PatternMatching
{
public class Program
{
public static void Main(string[] args)
{
string input = "You have 6 uncategorized contacts from <an id='316268655'>SAP SE</an>";
var parts = Regex.Split(input, @"(<an[\s\S]+?<\/an>)").Where(l => l != string.Empty).ToArray();
foreach(var a in parts)
{
Console.WriteLine(a);
break;
}
string pattern = "<an.*?>(.*?)<\\/an>";
MatchCollection matches = Regex.Matches(input, pattern);
if (matches.Count > 0)
foreach (Match m in matches)
Console.WriteLine(m.Groups[1]);
Console.ReadLine();
}
}
}
public class Program
{
public static void Main(string[] args)
{
string input = "You have 6 uncategorized contacts from <an id='316268655'>SAP SE</an>";
var parts = Regex.Split(input, @"(<an[\s\S]+?<\/an>)").Where(l => l != string.Empty).ToArray();
string part="";
foreach(var a in parts)
{
part =a;
if(a.Contains("<an")){
part = Regex.Replace(a, @"(?i)<(an)(?:\s+(?:""[^""]*""|'[^']*'|[^""'>])*)?>", "<$1>");
}
Console.WriteLine(part);
}
Console.ReadLine();
}
}