eScript example of using Regular Expression

Requierment:

You have a string of length n. You want to add symbol ~ after every X e.g. 20 characters of this string.

Solution:

var sourceStr = "This is a long string in which we need to insert ~ after every 20 characters";
var targetStr = sourceStr.replace(/.{1,20}/g, "$&~");