null check in replacesquarebrackets