whole word substitution in SED

I am trying to substitute something with sed and what I want is to substitute a whole
word and not part of a word. ie

sed 's/class/room/g' filename

will substitute both class and classes into room and roomes which is not what i want

Grep for instance can use the -w option or <>
grep -w class
and in that case it will not get classes.

Don't know about sed but wanted to implement something like that

sed 's/class /room /g' filename

Thank for your suggestion

That won't handle lines that end in 'class' or words that end in class (say 'p-class' for example).
I'd suggest looking for words that are proceeded by either a space or start of line, AND end in a space or end of line.

use:
sed 's/class\>/room/g' filename

the above will only replace lines that end with class and will ignore classes.

But that will replace class and whateverclass.

sed 's/^class$/room/g' filename

EDIT: This is WRONG, see post below!!

Then use this:

sed 's/\<class\>/room/g' filename

Should only replace words that start and end with class.

My bad you are correct.