Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

search a word between "( )" and apply CharacterStyle

Explorer ,
Jan 24, 2015 Jan 24, 2015

sorry my bad english

I need your help,

I can search within a parenthesis with \((.*)\)

ex:  hello (world) bye, need apply a CharacterStyle to "(world)" with  CharacterStyle


hello (world) bye

similar script:

var active_doc = app.activeDocument; 

 

var search_string = /\((.*)\)/ig;

 

var text_frames = active_doc.textFrames; 

var italicStyle = active_doc.characterStyles["italica"]; 

if (text_frames.length > 0) 

    for (var i = 0 ; i < text_frames.length; i++) 

      { 

          var this_text_frame = text_frames

  

  italicStyle.applyTo(this_text_frame.textRange); 

            

           if (new_string != this_text_frame.contents) 

               { 

                    this_text_frame.contents = new_string; 

               } 

      } 

thanks, sorry my bad english I speak spanish

TOPICS
Scripting
793
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 26, 2015 Jan 26, 2015

var frames = app.activeDocument.textFrames;

for (var j = 0; j < frames.length; j++){

var text = frames.textRange;

var italicStyle = app.activeDocument.characterStyles["italica"];

var haystack = text.contents;

var needle = /[\(]([^\)]*)[\)]/gi;

var match;

while(match = needle.exec(haystack)){

var start = needle.lastIndex - match[0].length;

var end = match[0].length;

for (var i = 0; i< end; i++){

italicStyle.applyTo(text.characters[i + start]);

}

}

}

Translate
Adobe
Guide ,
Jan 26, 2015 Jan 26, 2015

Try this.

var text = app.activeDocument.selection[0].textRange;

var italicStyle = app.activeDocument.characterStyles["italica"];

var haystack = text.contents;

var needle = /[\(]([^\)]*)[\)]/gi;

var match;

while(match = needle.exec(haystack)){

var start = needle.lastIndex - match[0].length;

var end = match[0].length;

for (var i = 0; i< end; i++){

italicStyle.applyTo(text.characters[i + start]);

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2015 Jan 26, 2015

You are awesome!!, thanks, but it may be possible to search in whole document or all layers?

thanks thanks!

sorry my bad english

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 26, 2015 Jan 26, 2015

var frames = app.activeDocument.textFrames;

for (var j = 0; j < frames.length; j++){

var text = frames.textRange;

var italicStyle = app.activeDocument.characterStyles["italica"];

var haystack = text.contents;

var needle = /[\(]([^\)]*)[\)]/gi;

var match;

while(match = needle.exec(haystack)){

var start = needle.lastIndex - match[0].length;

var end = match[0].length;

for (var i = 0; i< end; i++){

italicStyle.applyTo(text.characters[i + start]);

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2015 Jan 26, 2015

thank you very much , it works great, awesome script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 26, 2015 Jan 26, 2015

oops,

Update regex line to this...

var needle = /[\(]([^\)\(\r]*)[\)]/gi;

this makes sure the match does not have brackets within it and also no line breaks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2015 Jan 26, 2015

thank you very much , you are outstanding

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 26, 2015 Jan 26, 2015
LATEST

No problem, Glad I could help...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines