删除R中EURO符号后的字符 [英] Removing characters after a EURO symbol in R

查看:72
本文介绍了删除R中EURO符号后的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在"euro"变量中保存了一个欧元符号:

I have a euro symbol saved in "euro" variable:

euro <- "\u20AC"
euro
#[1] "€"

"eurosearch"变量包含此SOW中定义的服务,价格为15,896.80欧元(如果来回执行).

And "eurosearch" variable contains "services as defined in this SOW at a price of € 15,896.80 (if executed fro" .

eurosearch
[1] "services as defined in this SOW at a price of € 15,896.80 (if executed fro"

我希望欧元符号后的字符为"15,896.80(如果来回执行)" 我正在使用此代码:

I want the characters after the Euro symbol which is "15,896.80 (if executed fro" I am using this code:

gsub("^.*[euro]","",eurosearch)

但是我得到的结果是空的.如何获得预期的输出?

But I'm getting empty result. How can I obtain the expected output?

推荐答案

您可以通过使用

请参见 CodingGround演示

请注意,使用gsub("([^A-Za-z_0-9])", "\\\\\\1", euro)时,我会转义任何非单词符号,以便将$视为文字,而不是特殊的正则表达式元字符(取自

Note that with gsub("([^A-Za-z_0-9])", "\\\\\\1", euro) I am escaping any non-word symbols so that $ could be treated as a literal, not a special regex metacharacter (taken from this SO post).

这篇关于删除R中EURO符号后的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆