Reputation: 11
I have a question regarding the grep.
In the following text :
"there are 15 cats (10 black cats, 3 white ones, and 2 grey), but 4 of them are missing."
I wanna select the numbers but only the ones between parentheses (10, 3, and 2) And only the numbers. not the text nore the parentheses.
I've tried multiple syntax, some including lookbehind and lookahead positif but I can't manage to find the right awnser...
[edit] to be precise, what I want is to be able to apply a "character style" in the "grep style" section of "paragraph style" options. so it can't be a script but a single line of grep.
Thanks.
Upvotes: -1
Views: 376
Reputation: 14537
It's not clear what you're trying to gain. So here is a guess how you can apply the character style 'numbers' to the numbers between brackets with a script:
app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT);
function main() {
var founds = []; // all founds
app.findGrepPreferences = NothingEnum.NOTHING;
// Step 1. Find all texts between brackets
app.findGrepPreferences.findWhat = '\\(.+?\\)';
var texts_in_brakets = app.activeDocument.findGrep();
// Step 2. Find numbers inside the all found texts
while (text = texts_in_brakets.pop()) {
app.findGrepPreferences.findWhat = '\\d+';
var nums = text.findGrep();
while (num = nums.shift()) founds.push(num);
}
// Step 3. Apply the character style 'numbers' to the found numbers
var style = app.activeDocument.characterStyles.item('numbers');
while (found = founds.pop()) found.applyCharacterStyle(style, true);
}
Before:
After:
Upvotes: 0