Bug with Search and Replace when checking list with duplicate items? [SOLVED]

Thank you. I will check those links and see what I decide.
Appreciate your help with the solution for my issue with a simple JXA script.

1 Like

This won't work because you are S'n'Ring in the wrong place (similarly with your later attempt). You're searching each term in your temporary collection, whereas you should be searching the original variable. And you could still get weird results, as noted by @kevinb here, because you aren't doing "whole line" searches -- you need to anchor your regex and make the search multiline.

Which all turns into a bit of a mess...

The simpler way would be to S'n'R every "internal" line break with "," then prefix and postfix the whole string with " as well:

But -- and this is a big but -- it still isn't an AppleScript list. You're much better off keeping it as text, one "thing" per line, then doing the conversion in AS with the set myList to paragraphs of myText, as you did in the other thread.

My 2p is that they can both do the same when it comes to app integration (driving your apps, getting data in and out, etc), JavaScript is the more complete programming language and will serve you better in the long run, but AppleScript's "englishness" and better documentation for the app integration side of things makes it an easier start point, especially for those who just dip their toes in occasionally.

That said, if I was starting from scratch now -- JavaScript all the way, baby!

1 Like