Regex 使用正则表达式提取字符串
我可能没有使用正确的搜索词,因为我一直在查找 “匹配\验证”字符串与正则表达式(返回布尔值),而我想从其他字符串中提取一个字符串 如何使用正则表达式模式提取字符串的某些部分?这是您要查找的匹配项。Regex 使用正则表达式提取字符串,regex,c#-4.0,string-matching,Regex,C# 4.0,String Matching,我可能没有使用正确的搜索词,因为我一直在查找 “匹配\验证”字符串与正则表达式(返回布尔值),而我想从其他字符串中提取一个字符串 如何使用正则表达式模式提取字符串的某些部分?这是您要查找的匹配项。Regex.Match和Regex.Matches方法使用正则表达式查找字符串的一个或多个部分,并返回带有结果的Match或MatchCollection 例如: string input = "Some string with 123 numbers in it. Yeah 456!"; Match
Regex.Match
和Regex.Matches
方法使用正则表达式查找字符串的一个或多个部分,并返回带有结果的Match
或MatchCollection
例如:
string input = "Some string with 123 numbers in it. Yeah 456!";
MatchCollection result = Regex.Matches(input, @"\d+");
foreach (Match m in result) {
Console.WriteLine(m.Value);
}
输出:
123
456
你能提供更多的细节,也许是你想做什么的一个例子吗?我能用正则表达式来表示unicode字符吗(不是英语)?是的,你能。例如,
\d
代码匹配任何语言的数字,而不仅仅是阿拉伯数字(0-9)。