通过正则匹配查找处理文本内容
Match RegexStrTo(string str, string pattern)
{
Regex r = new Regex(pattern);
Match m = r.Match(str);
return m;
}
List<string> GetbundleURL(string path)
{
string bundleURL = "";
List<string> bundleUrList = new List<string>();
if (System.IO.File.Exists(path))
{
string scrTxt = System.IO.File.ReadAllText(path);
//去掉单行注释
for (int i = 0; i < 2; i++)
{
Match mstr = RegexStrTo(scrTxt, "(\\s//)(.*?)(\n)");//"//"开始 "\n"结束
while (mstr.Success)
{
string val = mstr.Value.ToString();
scrTxt = scrTxt.Replace(val, "\n");
mstr = mstr.NextMatch();
}
}
//去掉多行注释/**/
Match mMany = RegexStrTo(scrTxt, @"\/\*(\s|.)*?\*\/");
while (mMany.Success)
{
string val = mMany.Value.ToString();
scrTxt = scrTxt.Replace(val, "");
mMany = mMany.NextMatch();
}
//去掉所用空白字符,包括空格、制表符、换页符等
scrTxt = Regex.Replace(scrTxt, @"\s", "");
//Debug.Log(scrTxt);
//获取URL
Match m = RegexStrTo(scrTxt, "(\"url\")(.*?)(,)");//"url"开始 ,结束
while (m.Success)
{
string mValue = m.Value.ToString();
Debug.Log(mValue);
bundleUrList.Add(mValue);
//继续
m = m.NextMatch();
}
}
return bundleUrList;
}
本文详细探讨了如何使用正则表达式进行文本匹配,从特定字符开始到另一个特定字符结束,帮助读者掌握在文本处理中精准查找信息的技巧。
1580

被折叠的 条评论
为什么被折叠?



