Copy link to clipboard
Copied
I currently have a script that uses findGrep() to locate item numbers on a catalog page and then print the item number found and the page number it was on. I would like to modify this to also print the price of the item. The price occurs in the text somewhere following the item number and starts with a dollar sign followed by at least three digits (regex would be something like "\$[0-9][0-9][0-9]+"). How can I search for the price starting from the position of the found item number? Thanks
Copy link to clipboard
Copied
Hi Roger,
Code and screenshot please! ![]()
(^/)
Copy link to clipboard
Copied
Here is the code snippet that finds the item numbers ("SKU") in a catalog spread and prints them along with the page number. Many variable declarations not shown.
skus is the array of Text objects returned by findGrep().
// a regular expression to match item numbers/SKUs
var regex = "[0-9][0-9]-[0-9][0-9][0-9][0-9]+[A-Z]*";
[...]
// initialize search preferences
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences.findWhat = regex;
[...]
skus = doc.findGrep();
if ((nskus = skus.length) > 0)
{
// found at least one: process each SKU
for (j = 0; j < nskus; j++)
{
// get the SKU as a text object that we can manipulate with string methods
sku = skus
if ((hyphen = sku.indexOf("-")) > 1)
{
// well, of course there's a hyphen: it's part of our regex;
// we just don't want to print it
if (skus
{
// item is actually on the page, not on the pasteboard
websku = sku.substr(hyphen - 2, 2) + sku.substr(hyphen + 1);
file.write(websku + "\t" + skus
} // end if SKU is actually on a page (not on the pasteboard)
} // end if there's a hyphen in the SKU
} // end for each SKU
} // end if any SKUs present
[...]
Domo arrigato.
Copy link to clipboard
Copied
Let's not discuss this in the general forum, but in the more appropriate Scripting forum instead (where you also asked this: InDesign javascript: search for text that follows findGrep() result ).
Copy link to clipboard
Copied
Sorry, you're right. But I didn't discover the scripting forum until after I'd posted it here.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now