Adobe 65009333 Scripting Guide - Page 48
Using grep, to turn case sensitivity on
UPC - 883919155852
View all Adobe 65009333 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 48 highlights
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 findGrep and changeGrep methods. 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 changeGrepPreferences object. The following script 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; NOTE: The findChangeGrepOptions object lacks two properties of the findChangeTextOptions object: wholeWord and caseSensitive. This is because you can set these options using the regular expression string itself. Use (?i) to turn case sensitivity on and (?-i) to turn case sensitivity off. Use \> to match the beginning of a word and \< to match the end of a word, or use \b to match a word boundary.