5

I have a script to find all textframes in a document, and do a regular expression to remove (if contains) all text inside square brackets.

For example the text frame might contain:

"Lorem ipsum dolor sit amet, consectetur adipiscing elit [test] Lorem ipsum dolor sit amet, consectetur adipiscing elit [test2]"

i have written the following script to find all textframes content then replace them using regex, but only does 1 per text frame and doesnt apply to all

If i run the below script, it gets rid of [test] but not [test2]

var myFrames = app.activeDocument.textFrames;

for (var i = 0; i<myFrames.length; i++) {
   var myFrame = myFrames[i];
   var string = myFrame.contents;
   var string2 = string.replace(/ *\[[^\]]*]/, '');
   myFrame.contents = string2;
}
1
  • Im not too familiar with indesign which is why i thought a script would be the best idea, how do i use the GREP find/change to remove everything within square brackets? Thanks!
    – lanes123
    Apr 16, 2018 at 14:23

1 Answer 1

11

You don't need to script this, just

  • hit Ctrl+F and switch to the 'GREP' tab
  • type \[[^]]*\] in the 'Find what' field
  • or type the same thing with an \s? added in front to also remove any preceding whitespace, otherwise you'll be left with double spaces. so that's \s?\[[^]]*\]
  • make sure the 'Change to' field is empty
  • click 'Change All'

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.