Good morning,
I would like to rewrite a text and replace words that are often repeated.
Is it possible to replace a word by another word chosen at random from a list? ("women" by "girl or wife or female")
Is it possible to replace a word but not every time? For example every 3 occurrences?
For the moment i use
srt = srt.replace(/women/gi, 'girl');
thanks
This code should achieve what you are trying to accomplish.
My apologies. I thought this was Python by glancing at the code. Here is a Javascript version of the previous Python code.
For more info on using "indexOf" vs "includes" check out this article
JavaScript
Python
To do X amount of occurrences at a time change
blob.replace(word_to_replace, random_word, 1)toblob.replace(word_to_replace, random_word, 3). Note the number at the end. It means "how many occurrences at a time would you like to replace?"