Using Grep - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
6: Text and Type
Finding and Changing Text 102
HAPTER
var myDocument = app.documents.item(0);
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
//Search the document for the 24 point text and change it to 10 point text.
app.findTextPreferences.pointSize = 24;
app.changeTextPreferences.pointSize = 10;
myDocument.changeText();
//Clear the find/change preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;

Using grep

InDesign supports regular expression find/change through the
and
methods.
findGrep
changeGrep
Regular-expression find/change also can find text with a specified format or replace the formatting of the
text with formatting specified in the properties of the
object. The following
changeGrepPreferences
script fragment shows how to use these methods and the related preferences objects (for the complete
script, see FindGrep):
var myDocument = app.documents.item(0);
//Clear the find/change grep preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//Regular expression for finding an email address.
app.findGrepPreferences.findWhat = "(?i)[A-Z]*?@[A-Z]*?[.]...";
//Apply the change to 24-point text only.
app.findGrepPreferences.pointSize = 24;
app.changeGrepPreferences.underline = true;
myDocument.changeGrep();
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
N
: The
object lacks two properties of the
object:
OTE
findChangeGrepOptions
findChangeTextOptions
and
. This is because you can set these options using the regular expression
wholeWord
caseSensitive
string itself. Use
to turn case sensitivity on and
to turn case sensitivity off. Use
to match the
(?i)
(?-i)
\>
beginning of a word and
to match the end of a word, or use
to match a word boundary.
\<
\b
One handy use for grep find/change is to convert text mark-up (i.e., some form of tagging plain text with
formatting instructions) into InDesign formatted text. PageMaker paragraph tags (which are not the same
as PageMaker tagged-text format files) are an example of a simplified text mark-up scheme. In a text file
marked up using this scheme, paragraph style names appear at the start of a paragraph, as shown below:

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents