s/^ #start of string ( #start capture (?: #begin non-capturing repeating \[ #literal [ [^]]* #anything that isn't a ] ]\s* #ending ] and optional spaces )+ #end non capturing repeating ) #end capture / #end match $1
/gx;