I'm looking for help refactoring this messy code part.
It should handle the following house number formats
- 54 6 K 1 -> 546 K 1
- 54 6k 1 -> 546 K 1
- 20 H L -> 20 H L
- 1 10 -> 1 10
- 546 k1 -> 546 K 1
- 1K -> 1 K
?.toUpperCase()
?.match(/[^a-z]+|[a-z]|[a-z]/gi)
?.map((part) => `${part.trim()} `) // Split each part with a space
.toString() // Revert to one string
.replace(/,/g, "") // Remove all commas
.replace(/s+/g, " ") // Remove duplicate spaces
.trim(); // Remove and spaces
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…