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.
Looking for a regex
Moderator: General Moderators
Re: Looking for a regex
Can you describe the constraints in more detail? What is sometimes different? What is always the same?
Re: Looking for a regex
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 . '}');`
You can turn the above into an array by doing `$arr = json_decode('{' . $input . '}');`