Try this,
app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.findWhat = ".+"; app.findGrepPreferences.appliedParagraphStyle = "test"; //mention your paragraph style name var mySearch = app.activeDocument.findGrep(); myFrame = myDoc.textFrames.add ({geometricBounds:[".5in",".5in","5.5in","5.5in"]});//textframe will created in the first page of your InDesign document myFrame.insertionPoints[-1].contents = "CONTENTS\r"; for(i=0; i<mySearch.length; i++) { var mySearchContent = mySearch[i].contents; mySearchContent = mySearchContent.replace(/(\d+)(\t.+?\t)(.+?)(\t\d+)/g, '$1-$3'); myFrame.insertionPoints[-1].contents = mySearchContent + "\r" } app.findGrepPreferences = app.changeGrepPreferences = null;
Vandy