Sublime Forum

How to use REGEX in sublime to replace only the last occurrence in a line.

#1

I have an excel sheet with a list of model numbers if there is more than one model number in a cell it is seperated by a ", "

I want to add “, and” in between the second to last and last model number (if there is one).

example:

4, 6, 10 -> 4, 6, and 10
290 -> 290
40 -> 40
1630, 1640 ->1630, and 1640
abc, def, gh -> abc, def, and gh

How can I do this in sublime?

0 Likes

#2

Use replace, enable regex:

  • find : ,\s*\S+\s*$
  • replace: , and \1
1 Like