cclbc37 2021-06-14 20:11 采纳率: 81.8%
浏览 40
已结题

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;
        }
    }
}
  • 写回答

3条回答 默认 最新

  • qq_39609936 2021-06-15 17:09
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月27日
  • 已采纳回答 9月19日

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?