Looking for some help with RegEx as I do not use this very often. I could use the Parse tool but hoping to learn a bit more about RegEx. I am looking to take a string that has underscores and also varies in length. I am looking to exclude the far right of the string for each entry to include the last underscore. Any help appreciated.
Examples
123_12345_12345678910
12345_123456_12345678910
12_123456789_12345678910
Result
123_12345
12345_123456
12_123456789
Solved! Go to Solution.
Try (.+)_.+
This is saying, with the parentheses, to give you one or more characters before the last underscore, and ignore the underscore and anything afterwards.
Hi @cstafford ,
Here is a sample formula to output your expected result. I hope this helps.
Formula
Result = REGEX_Replace([Examples], "(.+_.+)_.*", "$1")
Output
Examples | Result |
123_12345_12345678910 | 123_12345 |
12345_123456_12345678910 | 12345_123456 |
12_123456789_12345678910 | 12_123456789 |
@cstafford (.+)([_]) will work in the RegEx tool with parse method. I couldn't determine based on your request if you wanted the last underscore or not, so I included it in the second output field instead ;)
@alexnajm I couldn't get your expression to work with the sample data.
@alexnajm That's funny. It works today. I'm not sure why it's different. It's literally the exact same expression!
Thanks for all the help here, greatly appreciated.