I am not a regex specialist unfortunately. So, I searched here and used some regex I found. That "half solves" my requirements already, now I search for the small missing piece.
In general, I am working on lines of code with PHP's built in tokenizer. At the end, I get a code string containing Whitespace, Tabs, and breaks. What I found here already cleaned this "unnecessary whitespace". But I would like to go a bit further:
$foo [ 'bar' ], $foo ['bar' ], $foo [ 'bar'] (containing some blanks)
should all go to: $foo['bar'] (no blanks anymore)
$foo [ "bar" ], $foo ["bar" ], $foo [ "bar"]
should go to: $foo ["bar"]
BUT: $foo [ 'this is different' ] shall go to $foo['tis is different'] (retaining the significant blanks)
At the moment I use:
$_S = array( " [", " '", "' ", " ]" );
$_R = array( "[", "'", "'", "]" );
$_tx = preg_replace( '/\s+/', ' ', $A_tx);
$_tx = str_replace( $_S, $_R, $_tx );
But for sure, the work can also be done with only one, more sophisticated regex?