const input = require('fs').readFileSync('/dev/stdin', 'utf8'); if (input.includes('w') && [...new Set([...input])].length - 2) { const len = Math.max(...input.match(/w+/g).map(v => v.length)); const re = new RegExp(`[^w]+w{${len}}`, 'g'); console.log( input.match(re).map(v => v.replace(/w/g, '')).join('\n') ); } else { console.log(''); }