Editing a string containing a word that can be converted to a number.

The tutorial on using Regex expressions by @StefanK and @technomorphh is certainly useful for users and impressive.

But in this particular case, I would just get the word -2 of each file’s basename and stick it to the beginning of the same name if it’s not already there. It would be 5 lines of code. :frowning:

It’s not quite as simple as that but it is pretty simple. There is a strange request about going back to 1894 (the beginning of movies, I guess) and making using different info.

Was it on this forum where I heard a quote like this:

I had problem I was trying to fix with coding, so used RegEx. Now I have two problems.

I used the ‘choose file’ so I could easily paste a functioning script here but use whatever serves your purposes.

As to the additional fields, it still should be possible to separate the fields so that you can retrieve the release year.

Since it will require multiple passes, any ‘set delimiter’ must be inside the repeat loop. We can add a second pass which will get the year. The beginning of the repeat loop should now look like this:

repeat with filmString in filmList
	
	set AppleScript's text item delimiters to "]"
	set split1 to last text item of filmString
        --> Various icons Dual 2021 (6,9) Oscar Best International Film. 4 nominations
	set AppleScript's text item delimiters to "("
	set rYear to last word of first text item of split1
        --> Various icons Dual 2021 
        --> 2021

Final output:
[format]“2003 Kill Bill Volume 1 [Quentin Tarantino] 2003 (7,6)
1907 20,000 Leagues Under the Sea [Georges Méliès] 1907 (6,0)
1945 The Stranger [Orson Welles] 1945 (7,4)
1979 1941 [Steven Spielberg] 1979 (5,5)
2021 Drive My Car (Doraibu mai kâ) [Ryûsuke Hamaguchi]Various icons Dual 2021 (6,9) Oscar Best International Film. 4 nominations”[/format]

If there are records that are still more complex, you can still likely dig deeper using more splits and possibly some if/then statements. Hope this helps.

That’s an old one.

I don’t remember where I first read it but I recall reading this 2008 blog post by Jeff Atwood, referring to a 1997 post (which I think I read but after it was written): https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/

It apparently goes back much further than that and was originally directed towards awk. Someone who looked into it wrote about their findings here: http://regex.info/blog/2006-09-15/247

Many thanks to all of you who have helped me.

You have not only helped me to catch a fish, but to receive valuable fishing lessons.

Regards. :smiley: