For Each and Search and Replace - the most confusing combination in KM

To get rid of the last comma, use this on the entire text, not line-by-line:

image

The regex is:

,\s*$

Without the (?m) option, "$" refers to the end of the entire string.

So this is basically searching for the last comma, optionally followed by whitespace (specifically in this case, a trailing linefeed).

But I think you can do it easier than that. You could probably do this in one regex expression, but I can't quite figure out how to add the first and last quote, so this will have to do:

image

If you're referring to regular expressions, it takes forever to learn them. But if you use them regularly (pun intended), you can eventually get there. My favorite website for testing them out is regex101.com, and I use it all the time to build regular expressions.

2 Likes