Skip to main content
Solved

Remove the last n delimeters from a string

  • September 12, 2024
  • 2 replies
  • 101 views

james_c_452
Enthusiast
Forum|alt.badge.img+8

Hi,

I keep going in circles and can’t think of an easy way to do this. Has anyone got any tips
Basically, I have an attribute such as “TEST_240829_MLS_5_316460_5816230”

What I what to do is remove “_316460_5816230” from the end. I’m wanting it to adaptively remove this part of the string from several thousand inputs.

Normally I would use the attribute trimmer however the length of this part of the string will change (not a constant thing I can remove). This part of the input string does always start at the second last occurrence on the “_” delimiter and go until the end. The amount of delimiters is not constant in the part of the string I want to keep though, so I also can’t use the attribute splitter and then rebuild the part I want from the parts of a list

Is there an easy wany to do this?

Best answer by bwn

Can use a RegEx solution to define RegEx Group 1 as being the text in front of the second last “_” and keep just this portion.

^(.+)_.*_.*$

 

Input

 

StringReplacer Output

 

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.

2 replies

bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • September 12, 2024

Can use a RegEx solution to define RegEx Group 1 as being the text in front of the second last “_” and keep just this portion.

^(.+)_.*_.*$

 

Input

 

StringReplacer Output

 


james_c_452
Enthusiast
Forum|alt.badge.img+8
  • Author
  • Enthusiast
  • September 12, 2024

I knew there was a way I’d done before. Thanks @bwn !