Looking for a regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
leon5wu
Forum Newbie
Posts: 1
Joined: Sun Aug 07, 2011 1:02 am

Looking for a regex

Post 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.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Looking for a regex

Post by McInfo »

Can you describe the constraints in more detail? What is sometimes different? What is always the same?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Looking for a regex

Post 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 . '}');`
Post Reply