🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8308

Re: Is it possible to use variables in Regex?

#8308
From: harbs
Date: Tue, 17 Oct 2006 08:00
71 lines
3830 bytes
I haven't been here in a while. Here it is:

var myDialog = app.dialogs.add({name:�Apply Character style between Characters�,canCancel:true}); 
with(myDialog){ 
   with(dialogColumns.add()){ 
      with(borderPanels.add()){ 
         with(dialogColumns.add()){ 
            staticTexts.add({staticLabel:�From Paragraph style:�}); 
            staticTexts.add({staticLabel:�Character style to apply:�}); 
            } 
         with(dialogColumns.add()){ 
            paraStyleDD = dropdowns.add( {stringList: [].concat( app.activeDocument.paragraphStyles.everyItem().name ), selectedIndex: 0,minWidth:170} ); 
            charStyleDD = dropdowns.add( {stringList: [].concat( app.activeDocument.characterStyles.everyItem().name ), selectedIndex: 0,minWidth:170} ); 
            } 
         } 
      with(borderPanels.add()){ 
         with(dialogColumns.add()){ 
            staticTexts.add({staticLabel:�Starting Character(s):�}); 
            staticTexts.add({staticLabel:�Ending Character(s):�}); 
            } 
         with(dialogColumns.add()){ 
            myPrefixField = textEditboxes.add({editContents:�(�,minWidth:99}); 
            mySuffixField = textEditboxes.add({editContents:�)�,minWidth:99});            } 
         } 
      with(borderPanels.add()){ 
         staticTexts.add({staticLabel:�Characters Between:�}); 
         with(dialogColumns.add()){ 
            with(myTypeRadioButtons = radiobuttonGroups.add()){ 
               radiobuttonControls.add({staticLabel:�No More Than:�, checkedState:true}); 
               radiobuttonControls.add({staticLabel:�No Less Than:�}); 
               myNumberOfCharactersField = integerEditboxes.add({editValue:20}); 
               } 
            } 
         } 
      } 
   } 
var myResult = myDialog.show(); 
if(myResult == true){ 
   MyNumberType = myTypeRadioButtons.selectedButton; 
   myNumber = Number (myNumberOfCharactersField.editContents); 
   myPrefix = myPrefixField.editContents; 
   mySuffix = mySuffixField.editContents; 
   paraStyleIdx = paraStyleDD.selectedIndex;  
   charStyleIdx = charStyleDD.selectedIndex;  
   myDialog.destroy(); 
   } 
else{ 
   myDialog.destroy(); 
   } 
    
MyparaStyle = app.activeDocument.paragraphStyles.item(paraStyleIdx); 
MycharStyle = app.activeDocument.characterStyles.item(charStyleIdx); 
doc = app.activeDocument

myStory = app.selection[0].parentStory; 
if (MyNumberType == 0){ 
   myRegexString = �[� + myPrefix + �][^� + mySuffix + �]{1,� + myNumber + �}[� + mySuffix +�]+�; 
   myChars = myStory.contents.match(myRegexString, �g�); 
   } else if (MyNumberType == 1){ 
   myRegexString = �[� + myPrefix + �][^� + mySuffix + �]{� + myNumber + �,}[� + mySuffix +�]+�; 
   myChars = myStory.contents.match(myRegexString, �g�); 
   } 
if( myChars != null )  
   {  
   app.findPreferences = app.changePreferences = null; 
   app.findPreferences.appliedParagraphStyle = MyparaStyle;  
   app.changePreferences.appliedCharacterStyle = MycharStyle;  
   for( i = 0; i < myChars.length; i++ ){  
      myStory.search( myChars[i], false, false,��); 
      } 
   }
Technical Details
Message-ID: <3bc1dce1.3@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.ecp.fr!news.stben.net!webcrossing
References: <3bc1dce1.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,35e61f302ee28709
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII
From: harbs@adobeforums.com
Newsgroups: adobe.scripting.indesign
Subject: Re: Is it possible to use variables in Regex?
Message-ID: <3bc1dce1.3@webcrossing.la2eafNXanI>
Date: Tue, 17 Oct 2006 01:00:05 -0700
References: <3bc1dce1.-1@webcrossing.la2eafNXanI>
Lines: 106
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.ecp.fr!news.stben.net!webcrossing