K B
asked on
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!
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!
I confirmed that _+[^_]*$ works in Notepad++ Replace as a REGEX, looks like a winner to me.
~bp
~bp
ASKER
And here is a test of the above regex... https://regex101.com/r/fJ6hO6/1
ASKER
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
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?
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?
What's different compared to test data you posted?
~bp
~bp
ASKER
Our comments just posted at the same time :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
awesome!
thank you!
thank you!
You're welcome!
Try this:
_+[^_\n]*$
~bp
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.