Answered
Is it possible to use Grep pattern with IndexOf()?
I use this code to find and select the next occurrence of a search string from cursor point, is it possible to do this with grep search patterns?
var doc = app.activeDocument;
var insertionPoint = doc.selection[0].insertionPoints[0];
// Get the text content following the insertion point
var text = insertionPoint.parent.characters.itemByRange(insertionPoint.index + 1, -1).contents;
// Convert the text content to a string
var textString = new String(text);
// Define the search string
var searchString = "ali";
// Find the next occurrence of the search string from the insertion point
var nextSearchString = textString.indexOf(searchString);
// Check if the search string is found
if (nextSearchString >= 0) {
// If found, move the insertion point to the next search string
foundtext = insertionPoint.parent.characters.itemByRange(insertionPoint.index + 1 + nextSearchString, insertionPoint.index + 1 + nextSearchString + searchString.length - 1);
// Select the next search string
foundtext.select();
}
