Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including replace-last with all npm packages installed. Try it out:

var replaceLast = require("replace-last")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

replace-last v1.2.6

JavaScript replaceLast function - Replaces last match for pattern in string with replacement


linux windows coverage
npm dependencies downloads node

JavaScript replaceLast function - Replaces last match for pattern in string with replacement


npm install --save replace-last

replace-last supports string and RegExp replacement. It works in Node code and browsers.

View the code | File size 1.7 KB | Fully unit tested | Zero dependency


var replaceLast = require('replace-last');
replaceLast(str, pattern, replacement);


<script src="node_modules/replace-last/replaceLast.js"></script>
  replaceLast(str, pattern, replacement);


str='' (string): The string to modify.

pattern (RegExp|string): The pattern to replace.

replacement (string): The match replacement.


(string): Returns the modified string.


replaceLast('hello hello hello', 'hello', 'bye');
// => 'hello hello bye';

replaceLast('hello hello hello', /he(ll)o/, 'rr');
// => 'hello hello herro';

replaceLast('hello hello hello', RegExp('.ell.'), 'bye');
// => 'hello hello bye'

replaceLast(777, 7, 8);
// => '778'

Author says

God is the last?

"Behold, I (Jesus) am coming quickly, and My reward is with Me, to give to each one according to the merit of his deeds (earthly works, faithfulness). I am the Alpha and the Omega, the First and the Last, the Beginning and the End [the Eternal One]."

Revelation 22:12-13 AMP

Jesus, King of Kings (first) put himself last - paying the death penalty for your wrongdoing - by willingly dying on the cross for you in your place.

He didn't do this because you loved Him. He did this even though you didn't love Him. He did this in the midst of all your hatred, your lust and worst of all, your apathy!

The nails never held him there, His love for you did! He commands men everywhere to repent and offers forgiveness for all them that believe!

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free