Yes, search eBay for a ‘DC Buck converter’. These are inexpensive devices that convert a higher voltage to a lower one, efficiently. Get one that is rated for more amps than you require.
You need to understand the capacity of your battery. a 18V 5AH battery has about 90 Watts of capacity. That means it can deliver approximately 18V at 1 Amp for 5 hours or 18V at 5 Amps for 1 Hour. When you convert the voltage to 12V, it will still deliver near 90 Watts, so you can get 12V at 1 Amp for 7.5 hours or 12V at 7.5 Amps for 1 hour.
If you look at your CPAP it will require 12V at some current level. As you can see, if it needs more than 1 Amp, a single 18V 5AH battery will only work for 7.5 hours. You can parallel the batteries together for nearly double the capacity.
Batteries do not supply voltage at a perfectly linear level, meaning they supply a higher voltage initially, and drop down lower as they discharge. Your DC Buck Converter will fix this problem, as it will supply a constant voltage output. Also, battery capacity lowers, as the current draw increases.