I know that this expression gets rid of non-alphanumeric characters:
sed 's/[^a-zA-z0-9]//g'
and I understand that it is replacing them with nothing - hence the '//'-, but I don't understand how it's doing it.
It seems it's finding strings that begin with alphanumeric and replacing them with nothing! Obviously that would not give the required output so I'm a little confused and clearly missing something...
The circumflex I marked in red in your code (and please use CODE tags) is not an anchor. When a circumflex is the first character in a matching expression (i.e., [expression specifying a set of characters to match] ), it specifies a non-matching expression where all of the characters except those specified by the expression following the circumflex will be matched. So, in this case everything that is not a lowercase letter, not an uppercase letter, and not a digit is removed (or, as you said, replaced by nothing).