I tried to stack two regex expressions, but without any luck.
In my case I need to find all words with length 50 and larger
\w{50,}
and now I need to split only those matches in chunks by 10 characters.
.{1,10}
I was unable to apply second expression to the first expression matches. Do you've any ideas?
Thanks!!!
Javascript replace() can take a function as replacement.
str = str.replace(/\w{50,}/, function(m) {
return m.match(/.{1,10}/g).join(' ');
});
See this demo at tio.run - or a bit shorter one:
str = str.replace(/\w{50,}/, m => m.match(/.{1,10}/g).join(' '));
No idea if it's possible in JS with just one regex. In PCRE: (?:\G\B|\b(?=\w{50}))\w{10}\B\K