string <- "B04 + B02 - A10mB03"gsub("(B[0-1][0-9]|A[126]0mB[0-1][0-9])", "raster(\\1)", string)gsub("(\\w+)", "raster(\\1)", string)
Standard input is empty
[1] "raster(B04) + raster(B02) - raster(A10mB03)" [1] "raster(B04) + raster(B02) - raster(A10mB03)"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!