// My Section -----------------------------------------------------------------
The above is the desired result.
Imagine this scenario
You can use callback function of replace and based on length you can replace values
let str = `// ----------------------------------------------------------------------------
// firebase
// ----------------------------------------------------------------------------
// utils`
let final = str.replace(/^.*$/gm, (match)=>{
return match.length === 0 ? match : match.length > 20 ? match.substr(0,20) : match + `-`.repeat(20-match.length)
})
console.log(final)