c# 正则表达式报错。

我特意去正则表达式网站测试了一下,没有错误啊,不知道为啥报错。翻译了一下错误是无效的模式在偏移量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;
        }
    }
}

把正则表达式前面的@去掉试一下

 

看提示的意思是,你的 (?!中间有空格了,(? !,在正则修饰中,如果出现问号修饰,问号后的修饰限定必须紧跟问号