Find and Replace Text with Multiple Rules (CSV upload)

This tool performs multiple find-and-replace operations at once on a piece of text that you supply. Create a CSV file with the strings you want to replace in the first column, and the substitution text in the second column:




Notes:

  • Case-sensitive matching. So any rules matching "apple" will not apply to the string "Apple".
  • This tool only works on exact search and replace values. Regex not supported. You can "view source" and adapt the code to your needs. I think you'll need to change the line
    targettext = targettext.replaceAll(data[currentrule][0], data[currentrule][1]);
    to something like
    var regEx = new RegExp(data[currentrule][0]);
    targettext = targettext.replaceAll(regEx, data[currentrule][1]);
    but it won't do "Capturing Groups" logic.
  • Think about how your search-and-replace rules will interact with each other. Rule #5 will not be operating on your original text - it will operate on the result of replacement rules #1, #2, #3 and #4...
  • Successfully tested on a 1.5mb text file, with a set of 15,235 replacement rules. I built this tool because this other tool from JoydeepDeb could not handle an operation this size.
  • This code runs in your browser - the text you enter and the .csv file never leave your computer. I do not have access to them.
  • Big "thank you" to Vanessa Fotso who's code & tutorial for handling CSV files in JavaScript I used for this project.
  • Also thank you to PictureElement on StackOverflow, who's answer about updating the DOM inside JavaScript loops was very helpful. That progress bar took longer than the substitution code...

If you loved this post you'll superlove my monthly emails ✉️


Comments

One response to “Find and Replace Text with Multiple Rules (CSV upload)”

  1. thank you so much, and correct!, the other tool from Joydeepdeb is very unstable and can´t handle much !. I translate spoken danish langguage in davinci resolve to subtitle, but davinci is crap as of right now, to fully understand danish, and spits out alot of wierd danish phrases so this tool is AWSOME! to find and replace wierd danish phrases tht davinci has come up with…hahaha.