Use regex to replace the last comma in a string with "and"

I have a string of text entered using a multiple choice option. I would like to replace the last comma in the string with the word and. This is the expression I am using, but I have been unsuccessful at getting it to work: regexReplace({Main Level Description}, ā€œ(.*)|ā€, "$1 and ")

This probably goes without saying, I have very limited coding experience. Knack support suggested using three text formula fields, on to extract up to the last coma, a second one to extract after the last comma and a third to combine the results.

Any help is greatly appreciated!

Hi,

You can actually do this with one Text Formula:

regexReplace({Main Level Description}, (,(?=[^,]*$)),  and)

Result:
Screen Shot 2022-02-07 at 8.39.30 PM

:+1:

Ian
Knack Pros

1 Like

Nice one Ian @KnackPros - Regex is super powerful but a complete mystery to me. :man_shrugging:
Super impressed :100:

1 Like

Thank Ian! This was super easy to implement and I’m sure will help many users in the future!

2 Likes