node.js - Easiest way to replace a specific word in text files (htm format) with Javascript -


i'd replace "xxx" word in text files (.htm if makes difference). guess need parse text files dom , find "xxx" word? difference between jsdom, cheerio , htmlparser2?

edit: example, @thijs:

const   textin = document.getelementbyid('text-input'),   textout = document.getelementbyid('output');  textout.value= textin.value.replace(/salami/g, 'chocolate'); 

yes, want, how load text files document. text files provided, rather not heavily modify them. jsdom, cheerio , htmlparser2 came when searched. correct templates, have construct own text files?

if want replace word inside piece of text, can use replace on input string. example below replaces salami chocolate. need regex g modifier or else first occurrence replaced.

const    textin = document.getelementbyid('text-input'),    textout = document.getelementbyid('output');      textout.value= textin.value.replace(/salami/g, 'chocolate');
p {    margin: 0 10vw;  }    textarea {    height: 40vh;    margin: 0 10vw 5vh;    width: 80vw;  }
<p>before:</p>  <textarea id="text-input">  landjaeger cupim doner tongue salami burgdoggen alcatra boudin kevin. t-bone pork loin pastrami pancetta boudin, frankfurter salami drumstick burgdoggen tail hamburger shoulder short loin bresaola. bacon spare ribs turducken, rump ribeye jowl pork loin chicken salami. pig rump chicken shank filet mignon ham hock turducken. sausage short loin prosciutto ribeye burgdoggen picanha salami swine frankfurter jowl spare ribs meatloaf. andouille shoulder spare ribs ham. tongue venison swine spare ribs.    burgdoggen frankfurter landjaeger bacon, bresaola t-bone turducken shankle prosciutto ground round flank. salami tail ham cow short ribs pork drumstick shoulder meatball. beef bresaola short ribs spare ribs capicola boudin, fatback t-bone rump ball tip leberkas pig short loin hamburger. shank boudin meatball salami bacon. kielbasa short ribs pork belly ribeye jerky strip steak venison short loin meatball pork chop. fatback meatball swine hamburger doner tail burgdoggen prosciutto shoulder meatloaf spare ribs short loin porchetta.  </textarea>    <p>after:</p>  <textarea id="output"></textarea>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -