I have a string in PHP which could look similar to the following:
$string = '"["1000: Person One","1001: Person 2","1002: Person Three"]"';
It is generated from a JSON Array. I need to write a regular expression to separate the JSON elements into a PHP array. I need to pull just the numbers before each colon out. I have tried the following code, with no success:
preg_match_all('/\"[^:]*:/',$string,$target_array); //No Success
preg_match_all(/\"\d*:/,$string,$target_array); //No Success
What I need is a regex which can pull any characters between a " and a :.
Of course, this leaves problems if a person's name happens to include a similar pattern. The best thing I could do would be to parse the JSON array into a PHP array. So as an alternate (and preferred) solution, a way to parse the JSON array into a PHP array would be spectacular. I have already tried to json_decode the string, but it always yields NULL.
Edit: As a curiosity, when I copy the string directly from output with no filtering and json_decode that, it converts to a PHP array perfectly.
$string?:.