ateciufit15
ateciufit15

Reputation: 81

regular expression, find text inside couple of curly brackets

i'm very new here and i hope i can explain my problem.

i've a string like this: "{sometext {'id':123,'email':'email1','pass':'pass1'},someothertext:{'id':456,'email':'email2','pass':'pass2'}}"

and i'd like to create an array like this: Array ( [0] => 'id':123,'email':'email1','pass':'pass1' [1] => 'id':456,'email':'email2','pass':'pass2')

i can't find the regular expression to do this... :(

well, it would be much better if i could access to the first id with $arr[0][0], first email with $arr[0][1]...etc.

can anyone help me please?? thanks a lot


sorry for the delay..and thank you all!! finally i succeeded :) i deleted the external braces, replaced single with double quotation marks and then used json_decoded (it's perfect!) thank you again!

Upvotes: 0

Views: 416

Answers (2)

buckley
buckley

Reputation: 14030

This regex can help

{(?:'([^']*)':([^,]*),?)*}

The first group will contain "id" and the second group "123"

Note that that if you do it with 1 regex you need a regex engine that supports multiple captures in the same group. The .NET regex engine can do this.

If not you need to make 2 passes with a regex each. Let me know how far you get with this answer.

Upvotes: 0

erickrf
erickrf

Reputation: 2104

The input string you describe seems to be in JSON format. There are a lot of libraries to read JSON data in a wide variety of languages, have a look at: http://www.json.org/

Upvotes: 2

Related Questions