I'm trying to use regex to add decimals to any numbers following dollar signs within a vector of strings. I've been partially successful thus far but am having trouble with instances that occur at the end of string. Here's an example of the issue:
ex <- tibble(strings = c("10/$20/$30", "$40/50/60", "$70.00/80/$90.00"))
gsub("(\\$[0-9]+)([^\\.])", "\\1\\.00\\2", ex$strings)
Which I believe to mean, to identify sub-strings which begin with a dollar sign and at least one digit but not followed by a period and replace them with the dollar sign and current digit(s) followed by a decimal and two zeroes... but which yields:
[1] "10/$20.00/$3.000" "$40.00/50/60" "$7.000.00/80/$9.000.00"
I see that it's returning the desired result for all dollar values not located at the end of a string but, as evidenced by the first and third string, it's clear that I'm still missing an ingredient.
It seems as though I have two problems, the first is matching strings that fall at the end of a string ($30) and the other is dollar values that already have decimals.