2

How to add a prefix such as, “negtag_”, to any word consecutive to “neither” in R?

For example,

Hello, regarding btc god, you need to check with btc god team. we dont really have any right to arrange airdrop for them neither have we promised... bytom never lie or cheat. 

Desired output:

Hello, regarding btc god, you need to check with btc god team. we dont really have any right to arrange airdrop for negtag_them neither have we promised... bytom never lie or cheat.

"negtag_" is here the prefix connecting to the word "them", since "neither" is the word after the consecutive word

Ottoooo
  • 25
  • 4
  • 1
    Maybe the duplicate is not what you need, your expected output is a bit unclear though. Could you make your question more [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – NelsonGon Jan 29 '20 at 16:02
  • Please read the link in my previous comment and edit your question accordingly. – NelsonGon Jan 29 '20 at 16:05
  • Hi, I tried to do that with reprex, but i dont get it what to do. I updated my question, hopefully it make more sense now. – Ottoooo Jan 29 '20 at 16:19

1 Answers1

3

We can use some RegEx:

gsub("(\\w+\\s(?=neither))","negtag_\\1",test, perl=TRUE)
[1] "Hello, regarding btc god, you need to check with btc god team. we dont really have any right to arrange airdrop for negtag_them neither have we promised... bytom never lie or cheat."

Data:

test<-"Hello, regarding btc god, you need to check with btc god team. we dont really have any right to arrange airdrop for them neither have we promised... bytom never lie or cheat."
NelsonGon
  • 13,015
  • 7
  • 27
  • 57