fork download
  1. string <- "B04 + B02 - A10mB03"
  2. gsub("(B[0-1][0-9]|A[126]0mB[0-1][0-9])", "raster(\\1)", string)
  3. gsub("(\\w+)", "raster(\\1)", string)
Success #stdin #stdout 0.16s 176384KB
stdin
Standard input is empty
stdout
[1] "raster(B04) + raster(B02) - raster(A10mB03)"
[1] "raster(B04) + raster(B02) - raster(A10mB03)"