[^\\]+)\\u002...">

Getting "Unterminated [] installed." Error in C #

I work with the following regex in C #

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

and get this error:

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

I'm kinda used to regular expressions, so correct me if I'm wrong. The regular expression should extract the URLs from the text match, for example:

URL = HTTP: //domain.com \ u0026

"URL = HTTP: //hello.com \ u0026

+5
source share
2 answers

You need to use the shorthand line:

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

Edit: However, I would change the regex to

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

Then the whole match is the URL itself. No need for a capture subgroup.

+7
source

You avoid one of the brackets with \], which means you have unterminated [.

- .NET, . ! \ \\.

, . , .

-, , - Derek Slager.

+6

All Articles