Page 1 of 1

Looking for a regex

Posted: Sun Aug 07, 2011 1:29 am
by leon5wu
I have a string like this.
"bar_1":"4","bar_2":"4","bar_3":"4","bar_4":"3","bar_5":"4","bar_6":"4","bar_7":"4","bar_8":"4", "foo_1":"4","foo_2":"4","foo_3":"4","foo_4":"3","foo_5":"4","foo_6":"4","foo_7":"4","foo_8":"4"
And i want to split it to two strings.
"bar_1":"4","bar_2":"4","bar_3":"4","bar_4":"3","bar_5":"4","bar_6":"4","bar_7":"4","bar_8":"4"
and
"foo_1":"4","foo_2":"4","foo_3":"4","foo_4":"3","foo_5":"4","foo_6":"4","foo_7":"4","foo_8":"4"
Can I use regex to do that? and what is the regex?

Thank you.

Re: Looking for a regex

Posted: Sun Aug 07, 2011 2:47 pm
by McInfo
Can you describe the constraints in more detail? What is sometimes different? What is always the same?

Re: Looking for a regex

Posted: Mon Aug 08, 2011 10:09 am
by tr0gd0rr
what about using json_decode() and working with the array using array_chuck() or iterating and finding keys that start with foo?

You can turn the above into an array by doing `$arr = json_decode('{' . $input . '}');`