Copy link to clipboard
Copied
I have a script that has been working perfectly that was written by pixxxel schubser​ (thank you!!)
Original discussion can be found here.....
https://forums.adobe.com/thread/1881921
So here is the issue that has popped up using this code:
#target illustrator
var doc = app.activeDocument
var allText = doc.textFrames;
var aCon;
for (var i = 0; i < allText.length; i++) {
aCon = allText.contents;
if (aCon.match(/_SWITCH|SWITCH_/) != null) {
aCon = aCon.replace(/_SWITCH|SWITCH_/, "");
aCon = "SWITCH - " + aCon;
allText.contents = aCon;
} else if (aCon.match(/_SW|SW_/) != null) {
aCon = aCon.replace(/_SW|SW_/, "");
aCon = "SWITCH - " + aCon;
allText.contents = aCon;
}
}
Here is a before and after the script.
The first 3 text frames are great. The next ones are the issue. How do I make my search specifically the characters shown? Only _SW or _SWITCH
Any help would be appreciated!
Hi wolfe,
try to change this line
} else if (aCon.match(/_SW|SW_/) != null) {
with this
} else if (aCon.match(/_SW(?!\w)|SW_/) != null) {
Have fun
Be sure: the more examples you give - the better the Regex works
(This snippet also not works correctly eg with SWITCHES or SWITCHING
Make the same in this case: add the negative lookahead (?!\w) in first Regex)
Copy link to clipboard
Copied
Hi wolfe,
try to change this line
} else if (aCon.match(/_SW|SW_/) != null) {
with this
} else if (aCon.match(/_SW(?!\w)|SW_/) != null) {
Have fun
Be sure: the more examples you give - the better the Regex works
(This snippet also not works correctly eg with SWITCHES or SWITCHING
Make the same in this case: add the negative lookahead (?!\w) in first Regex)
Copy link to clipboard
Copied
Perfect as always! Would you mind explaining the code to me for this?....
It is a RegExp that is....
_SW(?!\w)|SW_/
(?!\w)
means matches any character that is not followed by another character?
Copy link to clipboard
Copied
subieguy2 schrieb
(?!\w)
means matches any character that is not followed by another character?
… another word sign. This can be a letter or a digit.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now