2

what is the pattern for getting a-z, A-Z, 0-9, space, special characters to deteck url

This is my input string:

{id:1622415796,name:Vincent Dagpin,picture:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/573992_1622415796_217083925_q.jpg}

This is the pattern: so far

([a-z_]+):[ ]?([\d\s\w]*(,|}))

Expected Result:

id:1622415796
name:Vincent Dagpin
picture:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/573992_1622415796_217083925_q.jpg

the problem is i can't get the last part.. the picture url..

any help please..

8
  • 1
    Why can't you deserialize the JSON into an object instead? Commented Apr 19, 2012 at 13:35
  • Why do you parse it yourself? Use a JSON parser and stop worriing!? Commented Apr 19, 2012 at 13:35
  • Might I suggest json.codeplex.com which has done all the work for you already :) Commented Apr 19, 2012 at 13:36
  • 1
    What problem? That is probably more your issue than needing a regex. Commented Apr 19, 2012 at 13:37
  • 2
    stackoverflow.com/questions/6076310/… describes your actual problem and how to fix it. Don't use regex. It's insanity. ... just install the right .net servicepack for your machine. Commented Apr 19, 2012 at 13:51

2 Answers 2

2

If this is the only kind of json input you expect and further json parsing is very unlikely, a full json parser would be overkill.

A string split may be all you need, jsonString.Split(',', '{', '}'); The regex for that would be along the lines of [{},]([a-z_]+):[ ]?(.+?)(?=,|})

If you can modify the json string that's being sent, you can key the RegEx on something else, like double quotes. Here's one I'm using that requires knowing the json key name. System.Text.RegularExpressions.Regex("(?<=\"" + key + "\"+ *: *\"+).*(?=\")");

Sign up to request clarification or add additional context in comments.

1 Comment

If you try to select the value of a key anywhere in the json besides in the last element, this will take all the string after the match .*. If you know what character classes to expect you can use [a-zAZ]* instead.
0

I don't think a regex is the right solution. C# already contains the tools you need in JavaScriptSerializer. Check out the answer here to see how.

1 Comment

Try browsing the links/suggestions on this question, then: stackoverflow.com/questions/4427473/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.