如何使用两个分隔符保留单词/字符串的唯一部分?

时间:2021-07-19 21:44:31
//@john:awesome play @user2:great....//@user3:wow%oke"kakaa"
@user5:aha@user3:hello
@user6:helloow @user7:database @user1:ok

The result i want is the users, i.e the word/string between "@" and ":", i have tried to split

我想要的结果是用户,即“@”和“:”之间的单词/字符串,我试图分裂

text_1 = strsplit(as.character(df$text), '(?<=[^@])(?=@)', perl=TRUE)

but the result is not what i wish I want the result to be like the following

但结果不是我希望我希望结果如下所示

john user2 user3
user5 user3
user6 user7 user1

1 个解决方案

#1


1  

If string is your string, you can try:

如果string是你的字符串,你可以尝试:

  regmatches(gregexpr("(?<=@)[^:]+",string,perl=TRUE),x=string)[[1]]
  #[1] "john"  "user2" "user3" "user5" "user3" "user6" "user7" "user1"

#1


1  

If string is your string, you can try:

如果string是你的字符串,你可以尝试:

  regmatches(gregexpr("(?<=@)[^:]+",string,perl=TRUE),x=string)[[1]]
  #[1] "john"  "user2" "user3" "user5" "user3" "user6" "user7" "user1"