Using Grep - Adobe 65009333 - InCopy CS4 - PC Manual

Scripting guide: javascript
Hide thumbs Also See for 65009333 - InCopy CS4 - PC:
Table of Contents

Advertisement

Text and Type
Finding and changing text 48
You also can search for a string of text and apply formatting, as shown in the following script fragment
(from the FindChangeStringFormatting tutorial script):
//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;
app.findTextPreferences.findWhat = "WIDGET^9^9^9^9";
//The following line will only work if your default font
//has a font style named "Bold" if not, change the text to
//a font style used by your default font.
app.changeTextPreferences.fontStyle = "Bold";
//Search the document. In this example, we'll use the
//InCopy search metacharacter "^9" to find any digit.
var myFoundItems = app.documents.item(0).changeText();
alert("Changed " + myFoundItems.length + " instances of the search string.");
//Clear the find/change preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;

Using grep

InCopy supports regular expression find/change through the
and
methods.
findGrep
changeGrep
Regular-expression find and change also can find text with a specified format or replace text formatting
with formatting specified in the properties of the
object. The following script
changeGrepPreferences
fragment shows how to use these methods and the related preferences objects (for the complete script,
see FindGrep):
//Clear the find/change 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;
app.documents.item(0).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

Advertisement

Table of Contents
loading

This manual is also suitable for:

Incopy cs4

Table of Contents