I have been using regex (in textmate's find & replace tool) to reformat a table of values I've received into a PHP array.
I've got most of the way there - but struggling with the final change.
The current status:
$subSectors[1] = 'Crop & Animal Production, Hunting & Related Service Activities'; [1]
$subSectors[2] = 'Forestry & Logging'; [1]
I'm looking to batch replace (100s of lines) so that the final characters [\d{0-3}] move to be the main array key.
So the above two lines would become:
$subSectors[1][1] = 'Crop & Animal Production, Hunting & Related Service Activities';
$subSectors[1][2] = 'Forestry & Logging';
The end of line bracketed values can be 1-3 digits in length.
I can match the bracketed values using:
\[\d{0,3}]$
But at a loss of how to structure the replacement string.
The easiest way is to capture ( )
each group separate and then do your replacement.
Find: ^(\$\w+)(\[\d+\].*?)\s*(\[\d{0,3}\])$
Replace: $1$3$2