I posted these two links the other day, so good information.
Tire Sizing Systems
https://www.sheldonbrown.com/26.html
The 18/23 on the rim may be inner and outer widths. The 622 is bead seat diameter, that has to match for a rim and tire to work I'm pretty sure. I'd guess the 40/42 is more of a nominal sizing, not a true measurement and as such basically interchangeable.