Skip to main content
Solved

replace last comma with &

  • May 13, 2024
  • 1 reply
  • 59 views

nicholas
Contributor
Forum|alt.badge.img+14

I have an attribute containing String values such as

Gladstone Regional

Southern Downs Regional, Goondiwindi Regional

Moreton Bay City, Noosa Shire, Somerset Regional, Sunshine Coast Regional

I want to replace the last comma with “ &” so that the output will look like this

Gladstone Regional

Southern Downs Regional & Goondiwindi Regional

Moreton Bay City, Noosa Shire, Somerset Regional & Sunshine Coast Regional

Is there a way to use a Regular Expression inside the StringReplacer transformer to accomplish this?

Best answer by geomancer

Sure, this is called a 'Negative lookahead’.

In your case: ,(?!.*,) will do the trick.

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

geomancer
Evangelist
Forum|alt.badge.img+60
  • Evangelist
  • Best Answer
  • May 13, 2024

Sure, this is called a 'Negative lookahead’.

In your case: ,(?!.*,) will do the trick.