Skip to main content
Known Participant
November 18, 2022
Answered

Illustrator :: Find the Word

  • November 18, 2022
  • 1 reply
  • 1230 views

Hi All,

 

I’m relatively new at this. I’m making a script for a Illustrator file that has the words “New-Man”, “NewMan”, “New Man”, “New – Man”, etc.

 

The word “New-Man” is the right format so I need to find the remaining scenarios like “NewMan”, “New Man”, “New – Man”, etc. and write a error report in a excel file.

 

Please can any one help me to find this.

 

Thanks in advance!

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi pixxxel, I will not disagree with the regex king 🙂


Really? Is he here, too? And I thought we were alone.
😉

1 reply

CarlosCanto
Community Expert
Community Expert
November 18, 2022

this snippet finds all variations

 

var str = 'Im making a script for a Illustrator file that has the words “New-Man”, “NewMan”, “New Man”, “New – Man”, etc.'

var matches = str.match(/New.*?Man/g);
if (matches) {
    for (var a=0; a<matches.length; a++) {
        $.writeln(matches[a]);
    }
}
New-Man
NewMan
New Man
New – Man
Result: undefined

 

 

pixxxelschubser
Community Expert
Community Expert
November 18, 2022

Hi Carlos,

nice snippet.

🙂

 

How about a little expansion? 

 

var str = 'Im making a script for a Illustrator file that has the words “New-Man”, “NewMan”, “New Man”, “New – Man”, “new – Man”, “New – man”,  “new – man”,etc.'

var matches = str.match(/[Nn]ew.*?[Mm]an/g);
if (matches) {
    for (var a=0; a<matches.length; a++) {
        $.writeln(matches[a]);
    }
}
New-Man
NewMan
New Man
New – Man
new – Man
New – man
new – man
Result: undefined

 

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
November 18, 2022

Hi pixxxel, I will not disagree with the regex king 🙂


Really? Is he here, too? And I thought we were alone.
😉