Hello,

After reading help file, various threads on this board, and other online 
tutorials, I've attempted to use gsub (using Perl-like syntax) to change a 
currency string into something that can be converted to numeric type using only 
one regular expression.  Can anybody point out my error?  Note that 


>  x <- "\"$ 1,200,300,400.50\""

Tried the following in an attempt to arrive at "1200300400.50"

>  gsub("(^[\\D]*)(([\\d]*)[,])*([\\d]*[.]*[\\d]*)([\\D]*)", "\\3\\4", x, 
>perl=TRUE)
[1]  "300400.50"

Note that "\d" matches a digit character and "\D" matches a non-digit character.
Results group "\2" was intentionally omitted from the replacement pattern as it 
would have included commas.

I was expecting multiple results for group "\3"

Many thanks,
Mauricio

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to