Skip to content
Super fast recursive regex find and replacer
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__
src
.gitignore
.npmrc
.prettierrc
README.md
package.json

README.md

fast-replace

fast-replace installs ripgrep to recursively find and replace regex at blazing fast speeds

  • ~12x faster than other regex replacers (like replace)
  • recursive by default
  • respects .gitignore by default
  • matches file globs
  • supports regex capture groups

Installation

npm install -g fast-replace

Examples

Replace all occurrences of foo with bar recursively starting from the current directory:

fast-replace 'foo' 'bar'

Preview replacements without making any changes:

fast-replace 'foo' 'bar' -D

Replace occurrences in mock.js and files in the tests/ directory:

fast-replace 'foo' 'bar' mock.js tests/

Change snake_case to kebab-case:

fast-replace '(\S)_(\S)' '$1-$2'

Only include .js and .jsx files not found in vendor/:

replace 'foo' 'bar' -g '*.js' '*.jsx' -G 'vendor/**'

Options

fast-replace <from> <to> [paths...]

  <from>              Regex pattern to match
  <to>                String to replace matched pattern, use $1 to match regex
                      groups
  [paths...]          Directories or files to recursively search

Options:
  --dryrun, -D        Print replacements without making changes
  --quiet, -q         Shhh, don't print anything
  --unrestricted, -u  Don't respect .gitignore
  --ignoreCase, -i    Search with case insensitively
  --fixedStrings, -F  Treat pattern as a literal string instead of a regular
                      expression
  --globs, -g         Include files / directories matching the given globs
  --ignoreGlobs, -G   Exclude files / directories matching the given globs
  --version           Show version number
  --help              Show help

API

const fastReplace = require('fast-replace');

fastReplace('from', 'to', {
  quiet: true,
  paths: ['dir', 'file'],
  unrestricted: true,
  ignoreCase: true,
  fixedStrings: true,
  globs: ['*.js', '*.jsx'],
  ignoreGlobs: ['vendor/**'],
}).then(...)
You can’t perform that action at this time.