str.rsplit([sep[, maxsplit]])
Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done, the rightmost ones. If sep is not specified or None, any whitespace string is a separator. Except for splitting from the right, rsplit() behaves like split() which is described in detail below.
http://docs.python.org/library/stdtypes.html#str.rsplit
String.prototype.rsplit = function(sep, maxsplit) {
var split = this.split(sep);
return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
}
This one functions more closely to the Python version
"blah,derp,blah,beep".rsplit(",",1) // [ 'blah,derp,blah', 'beep' ]
You can also use JS String functions split + slice
Python:
'a,b,c'.rsplit(',' -1)[0]
will give you 'a,b'
Javascript:
'a,b,c'.split(',').slice(0, -1).join(',')
will also give you 'a,b'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With