我特意去正则表达式网站测试了一下,没有错误啊,不知道为啥报错。翻译了一下错误是无效的模式在偏移量12无法识别的分组构造,看不懂一脸蒙蔽。
using System;
using System.Text.RegularExpressions;
namespace 图床中转
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Users\ZOHO\Desktop\图床中转\The test data\【CSS样式】—超详细+实践_winnieFighting-CSDN博客.md";
string text = "";
string pattern = @"!\[.*\]\((? !http | https).*\)";
if (path == "")
{
Console.WriteLine("路径为空");
}
else
{
text = System.IO.File.ReadAllText(path);
System.Console.WriteLine("Contents of WriteText.txt = {0}", text);
GetPathPoint(text, pattern);
}
}
/// <summary>
/// 获取正则表达式匹配结果集
/// </summary>
/// <param name="value">字符串</param>
/// <param name="regx">正则表达式</param>
/// <returns></returns>
static float[] GetPathPoint(string value, string regx)
{
if (string.IsNullOrWhiteSpace(value))
return null;
Regex rgx = new Regex(regx);
bool isMatch = rgx.IsMatch(value);
if (!isMatch)
return null;
MatchCollection matchCol = Regex.Matches(value, regx);
float[] result = new float[matchCol.Count];
if (matchCol.Count > 0)
{
for (int i = 0; i < matchCol.Count; i++)
{
result[i] = float.Parse(matchCol[i].Value);
}
}
return result;
}
}
}