Copy link to clipboard
Copied
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
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]);
}
}
}
Copy link to clipboard
Copied
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]);
}
}
Copy link to clipboard
Copied
You are awesome!!, thanks, but it may be possible to search in whole document or all layers?
thanks thanks!![]()
sorry my bad english ![]()
Copy link to clipboard
Copied
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]);
}
}
}
Copy link to clipboard
Copied
thank you very much , it works great,
awesome script.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
thank you very much
, you are outstanding ![]()
Copy link to clipboard
Copied
No problem, Glad I could help...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now