Skip to content
Advertisement

Remove Last instance of a character and rest of a string

If I have a string as follows:

foo_bar_one_two_three

Is there a clean way, with RegEx, to return: foo_bar_one_two?

I know I can use split, pop and join for this, but I’m looking for a cleaner solution.

Advertisement

Answer

JavaScript

Which behaves like this:

JavaScript

See in the documentation entry for str.rsplit([sep[, maxsplit]]).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement