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日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效