获得"未终止的[]集"错误在C# [英] Getting "Unterminated [] set." Error in C#

查看:1924
本文介绍了获得"未终止的[]集"错误在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#以下的正则表达式的工作。

I am working with following regex in C#

Regex find = new Regex("[,\"]url(?<Url>[^\\]+)\\u0026");

和收到此错误:

"System.ArgumentException: parsing "[,"]url([^\]+)\u0026" - Unterminated [] set.

我是一种新的正则表达式正确等等。我,如果我错了,正则表达式应该是从文本中提取匹配的URL,如:

I'm kind of new to regular expressions so correct me if I'm wrong. The regular expression is supposed to extract urls from text matching like:

,URL = HTTP://domain.com\\\&

,url=http://domain.com\u0026

URL = HTTP://hello.com\\\&

"url=http://hello.com\u0026

推荐答案

你需要使用一个逐字字符串:

You need to use a verbatim string:

Regex find = new Regex(@"[,""]url(?<Url>[^\\]+)\\u0026");



编辑:不过,我正则表达式改为

However, I'd change the regex to

Regex find = new Regex(@"(?<=[,""]url=)[^\\]+(?=\\u0026)");



那么整个比赛是URL本身。不需要一个捕获子组

Then the entire match is the URL itself. No need for a capturing sub-group.

这篇关于获得&QUOT;未终止的[]集&QUOT;错误在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆