Reemplazar una subcadena que está entre corchetes con php regex

Aquí está la subcadena con la que estoy trabajando

[sitetree_link%20id=2] 

Necesito reemplazar todas las apariciones de% 20 que caen entre [] con un espacio en blanco. Pero obviamente, si hay% 20s fuera de [] llaves, déjalos en paz …

Estoy aprendiendo regex ahora, pero este parece bastante difícil. Alguien tiene una expresión cerebral súper inteligente para esto?

Gracias 🙂

Puedes intentar esto

 $result = preg_replace('/(\[[^]]*?)(%20)([^]]*?\])/m', '$1 $3', $subject); 

Explicación

 ( # Match the regular expression below and capture its match into backreference number 1 \[ # Match the character “[” literally [^]] # Match any character that is NOT a “]” *? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy) ) ( # Match the regular expression below and capture its match into backreference number 2 %20 # Match the characters “%20” literally ) ( # Match the regular expression below and capture its match into backreference number 3 [^]] # Match any character that is NOT a “]” *? # Between zero and unlimited times, as few times as possible, expanding as needed (lazy) \] # Match the character “]” literally )