I have text string such like this: Stoli 2.0 Intel PAV UMA, Phelps 1.0 Intel PAV_BayTrail x360
and I need to extract only the part Stoli 2.0 from the first one and Phelps 1.0 from the second one.
我有这样的文本字符串:Stoli 2.0 Intel PAV UMA,Phelps 1.0 Intel PAV_BayTrail x360,我需要从第一个中提取Stoli 2.0部分,从第二个中提取Phelps 1.0。
Could you anyone give me some sufficient solutio, how to do that, please? Thank you very much in advance.
你能不能给我一些足够的解决方案,请问怎么做?非常感谢你提前。
1 个解决方案
#1
You can use the gsub
function to do what you need:
您可以使用gsub函数来执行您需要的操作:
> x <- c("Stoli 2.0 Intel PAV UMA", "Phelps 1.0 Intel PAV_BayTrail x360")
> gsub("(^.* [0-9]*\\.[0-9]*).*", "\\1", x, perl = T, )
[1] "Stoli 2.0" "Phelps 1.0"
#1
You can use the gsub
function to do what you need:
您可以使用gsub函数来执行您需要的操作:
> x <- c("Stoli 2.0 Intel PAV UMA", "Phelps 1.0 Intel PAV_BayTrail x360")
> gsub("(^.* [0-9]*\\.[0-9]*).*", "\\1", x, perl = T, )
[1] "Stoli 2.0" "Phelps 1.0"