Regex - moving matched text to earlier in line

ste*_*eve 2 php regex textmate2

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]
Run Code Online (Sandbox Code Playgroud)

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';
Run Code Online (Sandbox Code Playgroud)

The end of line bracketed values can be 1-3 digits in length.

I can match the bracketed values using:

\[\d{0,3}]$
Run Code Online (Sandbox Code Playgroud)

But at a loss of how to structure the replacement string.

hwn*_*wnd 6

最简单的方法是单独捕获( )每个组,然后进行替换。

Find: ^(\$\w+)(\[\d+\].*?)\s*(\[\d{0,3}\])$
Replace: $1$3$2
Run Code Online (Sandbox Code Playgroud)

现场演示