
Security News
OpenClaw Skill Marketplace Emerges as Active Malware Vector
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.
replace-nth
Advanced tools
Replace only specific occurrences of a string. e.g. if the string exists 10 times, you can replace, say, the 3rd and 8th occurrences only, etc. Returns a new string with nth specific matches of a pattern replaced by a replacement. The pattern can be a str

Replace only specific occurrences of a string. e.g. if the string exists 10 times, you can replace, say, the 3rd and 8th occurrences only, etc. Returns a new string with nth specific matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match.
Install with npm:
npm i replace-nth --save-dev
var replaceNth = require('replace-nth');
replaceNth( params );
Params:
num (string): a number formatted as a string. 12 returns first match, [12] returns the first and second match, and so on. See the tests for more examples.pattern (regex|string): The actual pattern to find and replace nth timesreplacement (string): the replacement to usestr (string): the string to search for replacementsExample:
var params = {
// pass any string
str: 'aaaaaaaaaaaaaaa'
// The nth number of match(es) to replace
num: '[135]',
// The pattern to replace
pattern: /a/g,
// the replacement to use
replacement: 'B',
};
console.log(replaceNth(params));
//=> 'BaBaBaaaaaaaaaa'
Jon Schlinkert
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on May 21, 2014.
FAQs
Replace only specific occurrences of a string. e.g. if the string exists 10 times, you can replace, say, the 3rd and 8th occurrences only, etc. Returns a new string with nth specific matches of a pattern replaced by a replacement. The pattern can be a str
The npm package replace-nth receives a total of 8 weekly downloads. As such, replace-nth popularity was classified as not popular.
We found that replace-nth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.