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

Search for specific characters in a textFrame

Engaged ,
Jun 27, 2017 Jun 27, 2017

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.

Capture.JPG

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!

TOPICS
Scripting
592
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

Community Expert , Jun 27, 2017 Jun 27, 2017

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)

Translate
Adobe
Community Expert ,
Jun 27, 2017 Jun 27, 2017

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)

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
Engaged ,
Jun 27, 2017 Jun 27, 2017

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?

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
Community Expert ,
Jun 27, 2017 Jun 27, 2017
LATEST

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.

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