dimanche 21 août 2016

RegExp to replace matching parenthesis in nested structure [closed]

How can I replace a set of matching opening/closing parentheses if the first opening parenthesis follows the keyword array? Can regular expressions help with this type of problem?

In order to be more specific, I'd like to solve this using either JavaScript or PHP

// input
$data = array(
    'id' => nextId(),
    'profile' => array(
       'name' => 'Hugo Hurley',
       'numbers' => (4 + 8 + 15 + 16 + 23 + 42) / 108
    )
);

// desired output
$data = [
    'id' => nextId(),
    'profile' => [
       'name' => 'Hugo Hurley',
       'numbers' => (4 + 8 + 15 + 16 + 23 + 42) / 108
    ]
];

Aucun commentaire:

Enregistrer un commentaire