s/( # begin capture \[error\] # "error" in square brackets :) \s* # optional whitespace (?: # non capture \[ # literal [ [^\]]+ # 1 or more non "]" \] # literal ] )* # end non capture ) # end capture /$1
/x;