Transforming pattern with gsub

Viewed 66

Why does this:

gsub("([0-9])+(e)+(-)","\\1^x10^\\3",eg)

Turn this: eg<-5.4748554e-14

Into this:

5.4x10^-14

I want to make it this:

5.4748554x10^-14

1 Answers

Move + inside the parenthesis to make it a single first group match:

> gsub("([0-9]+)(e)+(-)", "\\1x10^\\3", eg)
[1] "5.4748554x10^-14"
> 
Related