как добавить префикс к последовательному слову в строке в R - PullRequest
2 голосов
/ 29 января 2020

Как добавить префикс, такой как «negtag_», к любому слову, следующему за «ни» в R?

Например,

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. 

Желаемый вывод:

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_" - здесь префикс, соединяющий слово "им", так как "ни" - это слово после последовательного слова

1 Ответ

3 голосов
/ 29 января 2020

Мы можем использовать некоторые 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."

Данные:

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."
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...