What you can do is define a simple space script function and use that for sorting (I asked ChatGPT to help with this, so I’m sure there’s a better way, this seems to work though):
```space-script
silverbullet.registerFunction({name: "sortableIp"}, ip => {
return ip.split('.')
.map(octet => ('000' + octet).slice(-3)) // Pad each octet with leading zeros and take the last three digits
.join('.');
});
```
Then in your query you can use order by sortableIp(ip)
Quick and dirty space lua version for V2 for those who come across this thread
```space-lua
function sortableIp(ip)
local parts = {}
for octet in string.gmatch(ip, "(%d+)") do
table.insert(parts, string.format("%03d", tonumber(octet)))
end
return table.concat(parts, ".")
end
```