I have code that detects various patterns in a text of strings (specifically it detects all numbers whether they are in digit form, text form, have decimals, have dollar signs, etc.). I have stored all these patterns in a variable called "nums". (don't worry about the errors in my pattern that is not what i'm focusing on)
nums <- paste(digiNums, dollaCommaNums, dollaDeciNums, textNums, romaNums, sep = "|")
> nums
[1] "(\\d+)|([\\$£]?\\d{1-3}(,\\d{3})+)|([\\$£]?(\\d+)?\\.\\d+)|Zero|One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven|Twelve|Thirteen|Fourteen|Fifteen|Sixteen|Seventeen|Eighteen|Nineteen|Twenty|Thirty|Fourty|Fifty|Sixty|Seventy|Eighty|Ninty|Hundred|Thousand|Million|Billion|Trillion|\\b(M{1,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})|M{0,4}(CM|C?D|D?C{1,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})|M{0,4}(CM|CD|D?C{0,3})(XC|X?L|L?X{1,3})(IX|IV|V?I{0,3})|M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|I?V|V?I{1,3}))\\b"
linesNums <- grep(nums, lines, value = TRUE)
Now I am trying to modify my text so that it adds highlights (<< >>) to every number detected using my patterns stored in "nums". so the end result would be something like this:
#example text:
I am <<twenty>> years old.
I have <<$50.45>> in my pocket.
This tree is <<100,000>> years old.
How do I accomplish this? when I tried using gsub my end was result was:
linesNums <- cat(gsub(nums, "<<\\1>>", linesNums))
I am <<nums>> years old.
I have <<nums>> in my pocket.
This tree is <<nums>> years old.