Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何匹配角色后的所有内容_C#_Regex - Fatal编程技术网

C# 如何匹配角色后的所有内容

C# 如何匹配角色后的所有内容,c#,regex,C#,Regex,我几乎得到了这个答案。我想匹配冒号和空格后面的所有内容 所以如果我有这些线 你叫什么名字:阿兰 你的专业是什么:计算机科学 我想捕获“Alain”和“计算机科学” 我有这个正则表达式 (?<=:)\s*\w* (?可能会有一些不太详细的方法来实现这一点,但这是可行的 (?<=What is your name: )(.*)(?= What is your major:)|(?<=What is your major: )(.*) (?可能会有一些不太详细的方法来实现这一点

我几乎得到了这个答案。我想匹配冒号和空格后面的所有内容

所以如果我有这些线

你叫什么名字:阿兰
你的专业是什么:计算机科学
我想捕获
“Alain”
“计算机科学”

我有这个正则表达式

(?<=:)\s*\w*

(?可能会有一些不太详细的方法来实现这一点,但这是可行的

(?<=What is your name: )(.*)(?= What is your major:)|(?<=What is your major: )(.*)

(?可能会有一些不太详细的方法来实现这一点,但这是可行的

(?<=What is your name: )(.*)(?= What is your major:)|(?<=What is your major: )(.*)
(?也许您可以使用冒号和零个或多个空格并将其拆分

也许您可以使用冒号和零个或多个空格来分隔

(此正则表达式与实现无关,应与任何正则表达式库一起使用)

如果您使用的是捕获组,这将捕获您要查找的内容,但将匹配冒号和空格

(此正则表达式与实现无关,应与任何正则表达式库一起使用)


如果您使用的是捕获组,这将捕获您正在查找的内容,但将匹配冒号和空格。

您可以按照上面的建议使用拆分。但是如果您确实必须使用正则表达式,则以下内容适用于您的字符串

string line1 = "What is your name: Alain";
Regex rgex = new Regex(@"(?<=:\s)(.*)", RegexOptions.Compiled);
Match match = rgex.Match(line1);            

if (match.Success)
{
    Console.WriteLine("Name= " + match.Value);
}

Console.ReadKey();
string line1=“你叫什么名字:阿兰”;

Regex rgex=new Regex(@)(?您可以按照上面的建议使用split

string line1 = "What is your name: Alain";
Regex rgex = new Regex(@"(?<=:\s)(.*)", RegexOptions.Compiled);
Match match = rgex.Match(line1);            

if (match.Success)
{
    Console.WriteLine("Name= " + match.Value);
}

Console.ReadKey();
string line1=“你叫什么名字:阿兰”;

Regex rgex=new Regex(@“(?也许
)(?arg我讨厌编辑!我应该看看为什么Regex?一个简单的
拆分
就可以了。拆分更简单吗?更快吗?对不起,我只上了一年学。也许
(?arg我讨厌编辑!我应该看看为什么正则表达式?一个简单的
拆分
就可以了。拆分更简单吗?更快吗?对不起,我只有一年的学习时间。谢谢!对不起,耽搁了。我有一个微积分考试要学习。一切都停止了。谢谢!对不起耽搁了。我有一个微积分考试要学习。一切都好吗我停下来。
: (.*)
string line1 = "What is your name: Alain";
Regex rgex = new Regex(@"(?<=:\s)(.*)", RegexOptions.Compiled);
Match match = rgex.Match(line1);            

if (match.Success)
{
    Console.WriteLine("Name= " + match.Value);
}

Console.ReadKey();