This project has moved and is read-only. For the latest updates, please go here.

Parsing Regular Expressions

Jul 8, 2010 at 1:19 PM
Edited Jul 8, 2010 at 1:29 PM
I have a JSON string that contains a Regular Expression.
  "regex": /[0-9]/i
When I try to parse this into a JSON object using :
JObject.Parse("..... above mentioned string.....");
I am getting the following exception:
Error parsing comment. Expected: *. Line 2, position...
   at Newtonsoft.Json.JsonTextReader.ParseComment()
   at Newtonsoft.Json.JsonTextReader.ParseValue(Char currentChar)
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
   at Newtonsoft.Json.Linq.JObject.Parse(String json)
Any ideas as to what I am doing wrong would be helpful. Thanks!
Jul 9, 2010 at 12:12 AM

Json.NET doesn't handle parsing regular expression values. I'll look at adding them some time in the future but right now you'll have to convert it to a string first.

Jul 9, 2010 at 6:32 AM
Thanks James. Look forward to the new additions.