How to remove the last word in a string only if it is a specific word?

Hello, I have a list of strings that mostly end with the word "in" and I need to remove the "in" from the end of each string. I can't just delete every instance of "in" because it is also legitimately present in some strings.

I used
value.partition(smartSplit(value," ")[-1])[0]

and it mostly worked, but it removed everything in the string after the first instance of "in." Is there a way to make it remove only the actual last word, not the first instance of a match with the last word plus everything after it?

You can use regular expressions for that.

value.replace(/ in$/, "")

The $ is a regular expression marker for the end of the text. Meaning only the word in at the end will get replaced.
You can also use regular expressions in the replace dialog.

For writing and understanding regular expressions there are online tools like https://regex101.com/ and https://regexr.com/.

It worked perfectly! Thank you, and thank you also for the additional suggestions :slight_smile: