Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在字符串中的模式之前提取数字_R - Fatal编程技术网

R 如何在字符串中的模式之前提取数字

R 如何在字符串中的模式之前提取数字,r,R,我有这样的句子: string <- "This is: the first/ part 123 EUR then the second part." 有人能帮我从绳子上提取123欧元后的硬币吗?非常感谢。这是您想要的吗: gsub( "[0-9]" , "", "This is: the first/ part 123 EUR then the second part." ) 如果要保留这些号码: stringr::str_extract( "This is: the first

我有这样的句子:

string <- "This is: the first/ part 123 EUR then the second part." 

有人能帮我从绳子上提取123欧元后的硬币吗?非常感谢。

这是您想要的吗:

gsub( "[0-9]" , "", "This is: the first/ part 123 EUR then the second part." )
如果要保留这些号码:

stringr::str_extract(  "This is: the first/ part 123 EUR then the second part." ,"[0-9]+" )

这是您想要的吗:

gsub( "[0-9]" , "", "This is: the first/ part 123 EUR then the second part." )
如果要保留这些号码:

stringr::str_extract(  "This is: the first/ part 123 EUR then the second part." ,"[0-9]+" )

不清楚模式,如果是欧元,那么

在更新的字符串中,它可以是

string <- "Time Interval [08:00-20:00]1,3 EUR/min." 
str_extract(string, "\\d+(,\\d+)?(?= EUR)")
#[1] "1,3"

不清楚模式,如果是欧元,那么

在更新的字符串中,它可以是

string <- "Time Interval [08:00-20:00]1,3 EUR/min." 
str_extract(string, "\\d+(,\\d+)?(?= EUR)")
#[1] "1,3"
在基数R中,我们可以使用sub来提取一个带有可选逗号的数字,另一个数字后跟EUR

同样的模式也可以用于更新的字符串

string <- "Time Interval [08:00-20:00]1,3 EUR/min." 
sub(".*?(\\d+(,\\d+)?)\\s+EUR.*", "\\1", string)
#[1] "1,3"
在基数R中,我们可以使用sub来提取一个带有可选逗号的数字,另一个数字后跟EUR

同样的模式也可以用于更新的字符串

string <- "Time Interval [08:00-20:00]1,3 EUR/min." 
sub(".*?(\\d+(,\\d+)?)\\s+EUR.*", "\\1", string)
#[1] "1,3"

到目前为止你试过什么?很多关于这些工作的想法?非常感谢。我已经在@akrun already的帮助下解决了这个问题。到目前为止,你尝试了什么?很多关于这些工作的想法?非常感谢。在@akrun alreadysting@Liselotte的帮助下,我已经解决了这个问题。我希望得到1,3个预期输出。你能解释一下\\d+,\\d+??=EUR的意思吗?string@Liselotte我希望得到1,3个预期输出。你能解释一下\\d+,\\d+??=EUR的意思吗?