Copy link to clipboard
Copied
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!
Hi pixxxel, I will not disagree with the regex king 🙂
Really? Is he here, too? And I thought we were alone.
😉
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi pixxxel, I will not disagree with the regex king 🙂
Copy link to clipboard
Copied
Really? Is he here, too? And I thought we were alone.
😉
Copy link to clipboard
Copied
Its working fine, thank you so much.