作业帮 > 综合 > 作业

c#获取文章中 开头是abc结尾是123的所有词,有什么好的算法!

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/17 21:14:10
c#获取文章中 开头是abc结尾是123的所有词,有什么好的算法!
使用正则表达式,需要引用using System.Text.RegularExpressions;方法如下:string pattern = @"abc.*?123";
string strTest = "123abcde123134e我们是abc你们是123";
Regex regex = new Regex(pattern);
MatchCollection matches = regex.Matches(strTest);
foreach (Match match in matches)
\x09Console.WriteLine(match.Value);输出为:
abcde123abc你们是123
希望对你有帮助.