Token by token:
sed -- you got that right
s/ -- substitute the following with FOO
^ -- beginning of line
\( -- begin group (which you call buffer)
[^:]* -- match any number of any char that's not a colon; `*' means any number of (what preceeds it); [^abcd] means "anything except abcd" (in this case it's just `:').
: -- then match a colon
[^:]* -- then match any no. of not-colon again
\) -- end group 1
333331 -- the text you want to be replaced with (some other text).
\([^:]*:\) -- should be more or less obvious
/ -- # FOO begins here
\1 -- the contents of group 1 (i.e. everything up until 333331)
OOO -- the replacement text.
\2 -- the rest of the line.
/ -- # FOO ends here
Also I would think that the command would need to end with `g'.
No--`g' means `global'. That is, replace *all* occurences of the pattern, not just the first. But since you only want to replace one pattern (the first), you don't need the g here.
I think this is more elegant, more correct and possibly faster too:
$ sed -r 's/^([^:]*:)333331/\1777771/' filename
It might be that `\1777771' gets interpreted as group number 1777771; try `\1(777771)' instead.
If all else fails, RTM