A string may contain non-number in braces which needs to be deleted. Input can be multiline too, for example :
input:
# (1437)
# {19} (917) (1437)
# {19} (1437) [1449] [2474] [2098] [1351] [508] [969]( MONDAY) [sunday]
desired output:
# (1437)
# {19} (917) (1437)
# {19} (1437) [1449] [2474] [2098] [1351] [508] [969]
However the below regex instead of removing just ( MONDAY) [sunday] removes the last line completely.
$re = '/^(#\h*)((\[\d+]|\{\d+}|\(\d+\))(?:\h+(?3))*)$/m';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
echo implode("\n", array_map(fn($x) => $x[1] . implode(' ', array_unique(explode(' ', $x[2]))), $matches));