Okay, here's a script that implements the above logic.
- Mark
/**
* Applies a paragraph style to any paragraph
* following a paragraph containing parentheses.
* @7111211 m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/grep-for-looking-for-a-specific-character-in-previous-line/m-p/13918906
*/
function main() {
var doc = app.activeDocument,
// the grep to find the paragraph after
// a paragraph containing parentheses
myFindWhat = '\\([^\\)\\r]+\\).*\\r\\K.*',
// put your paragraph style name here
changeToStyleName = "MyAfterParenthesesStyle",
// get the paragraph style
changeToStyle = doc.paragraphStyles.itemByName(changeToStyleName);
if (!changeToStyle.isValid) {
alert('There is no paragraph style named "' + changeToStyleName + '".');
return;
}
// the find/change grep
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = myFindWhat;
app.changeGrepPreferences.appliedParagraphStyle = changeToStyle;
doc.stories.everyItem().paragraphs.everyItem().changeGrep();
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Format Paragraphs");