regex - Removing characters after a EURO symbol in R -


i have euro symbol saved in "euro" variable:

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

and "eurosearch" variable contains "services defined in sow @ price of € 15,896.80 (if executed fro" .

eurosearch [1] "services defined in sow @ price of € 15,896.80 (if executed fro" 

i want characters after euro symbol "15,896.80 (if executed fro" using code:

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

but i'm getting empty result. how can obtain expected output?

you can use variables in pattern concatenating strings using paste0:

euro <- "€" eurosearch <- "services defined in sow @ price of € 15,896.80 (if executed fro" sub(paste0("^.*", gsub("([^a-za-z_0-9])", "\\\\\\1", euro), "\\s*(\\s+).*"), "\\1", eurosearch)  euro <- "$" eurosearch <- "services defined in sow @ price of $ 25,196.4 (if executed fro" sub(paste0("^.*", gsub("([^a-za-z_0-9])", "\\\\\\1", euro), "\\s*(\\s+).*"), "\\1", eurosearch) 

see codingground demo

note gsub("([^a-za-z_0-9])", "\\\\\\1", euro) escaping non-word symbols $ treated literal, not special regex metacharacter (taken this post).


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -