Copy link to clipboard
Copied
Hi
I wanna find a pattern and then add something to that and search it again here my code
app.findGrepPreferences.findWhat = "^PP[0-9]{6,6}?$";
var skunumber=app.activeDocument.findGrep();
var skupp= skunumber+"-pp"
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = skupp;
var finds = doc.findText();
if (finds.length > 0) {
alert("Found " + finds.length + " items, the first of them is on page " + finds[0].parentTextFrames[0].parentPage.name);
}
else {
alert("Nothing has been found");
}
app.changeGrepPreferences.changeTo = finds[0].parentTextFrames[0].parentPage.name;
alert(app.activeDocument.changeGrep().length);
app.activeDocument.changeGrep();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
but it doesn't find the skupp ?
how can I user the grep find value in my code?
here some the solution:
Since contents
is a simple Javascript string (not native InDesign text anymore), you can use Javascript's own match
function:
app.findGrepPreferences.findWhat = "(\\d)+(\\d)";
found = app.activeDocument.findGrep();
m = found[0].contents.match (/(\d)+(\d)/);
alert (m.join('\n'));
Copy link to clipboard
Copied
here some the solution:
Since contents
is a simple Javascript string (not native InDesign text anymore), you can use Javascript's own match
function:
app.findGrepPreferences.findWhat = "(\\d)+(\\d)";
found = app.activeDocument.findGrep();
m = found[0].contents.match (/(\d)+(\d)/);
alert (m.join('\n'));
Copy link to clipboard
Copied
Since
contents
is a simple Javascript string (not native InDesign text anymore) …
Hi,
FWIW: The value of text.contents could also contain values like special characters expressed as enumerators.
Code and result:
app.findGrepPreferences.findWhat = "\\X";
var found = app.activeDocument.findGrep();
for(var n=0;n<found.length;n++)
{
$.writeln(n+"\t"+found
.contents.constructor.name); };
/*
0 Enumerator
1 Enumerator
2 String
*/
Simple text frame in the document:
Regards,
Uwe