I am trying to code up an html tagging tool for my code in R and I am having difficulty finding and replace numbers with colored numbers.
I think the following is in the right direction but I am not sure what to do:
txt <- gsub("\\<[:digit:]\\>", paste0(num.start,"\\1",num.end) , txt)
This does not seem to do the job. Overall, I would like all numbers which are not part of words to be identified and replaced with tags before and after the numbers which change the color and are defined by the num.start, num.end variables.
For example:
num.start <- '<span style="color: #990000"><b>'
num.end <- '</b></span>'
So I would like to be able to feed in say R code and have it write html tags when appropriate.
Rcode:
txt <- "a <- 3945 ; b <- 3453*3942*a"
gsub("\\<[:digit:]\\>", paste0(num.start,"\\1",num.end) , txt)
[1] "a <- <span style="color: #990000"><b>3945</b></span> ; b <- <span style="color: #990000"><b>3453</b></span>*<span style="color: #990000"><b>3942</b></span>*a"
The hope would be that I could copy the modified R code into an html editor such as my blog and all of the numbers would be color coded.
Thanks so much for any assistance! Francis