Regex to find the last underscore and all text that follows it

My sample text would be something like this list

alpha123_4rf_Joe
45beta_Frank
Red5Great_Sam_Fun

and I would like to be left with (with a notepad++ regex find and replace)

alpha123_4rf
45beta
Red5Great_Sam

I am just looking for the Regex as I understand notepad++ :-)

Thank you!
LVL 8
K BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
The regex in the comment that you posted (and deleted) should work, although you should also be able to simplify that to...

_+[^_]*$

Open in new window


I don't know Notepad++ so I am not sure exactly how it would apply a regex but you may need to specify options to make it a "multiline" match and to match "globally" or all occurrences. Also, it may be obvious, but the replacement string should be just empty.
1
Bill PrewCommented:
I confirmed that _+[^_]*$ works in Notepad++ Replace as a REGEX, looks like a winner to me.

~bp
0
K BAuthor Commented:
Thank you for your replies.. it seems to not stop at the end of the line and highlight four additional lines (randomly?)
2015-09-08_2058.png
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
And here is a test of the above regex...   https://regex101.com/r/fJ6hO6/1
0
K BAuthor Commented:
Here is a better example... perhaps I should have given this to begin with..

MEX05\c.frank_plaCAAD6
MEX05\e.steve_playa6CE8F
MEX05\d.harry
MEX05\kdog
MEX05\scat
MEX05\j.rabbit
MEX05\c.mark_play79B61
MEX05\l.fancy
MEX05\n.pants
MEX05\a.farley
MEX05\davidspade

Open in new window

0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
It's very hard with the blurred image to know what is going on, but I understand that there might be data that you can't share with us!

Does the regex work with the original sample text? Can you come up with some sample text that DOES exhibit the issue that you have but that is non-sensitive data so that you can fully post it here?
0
Bill PrewCommented:
What's different compared to test data you posted?

~bp
0
K BAuthor Commented:
Our comments just posted at the same time :-)
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Ok, try this...

_+[^_]*?$

Open in new window


And a test link... https://regex101.com/r/fJ6hO6/2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K BAuthor Commented:
awesome!
thank you!
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome!
0
Bill PrewCommented:
Try this:

_+[^_\n]*$

Open in new window

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.