Why even bother with the CSS class? Just apply text-wrap: nowrap; to all <code> elements and dispense with the fragile regex parsing.
The 5 cm example had a line break between the 5 and the cm when I read the page in my phone. A joke?
Unfortunately this makes it much harder to read on narrow-width screens (e.g. mobile), where the use must scroll horizontally
You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML.