I'm trying to use replace-regexp to change the following code
samples <- rep(10, 5)*1000 ## steps determined by samples * thin
adaptive.ratio <- c(rep(c(1,0), 2), 0) ## Alternate between adaptive and non-adaptive
...
to
print(paste0("samples: ", samples)) ## steps determined by samples * thin
print(paste0("adaptive.ratio: ", adaptive.ratio)) ## Alternate between adaptive and non-adaptive
...
I am using the following regexp to do so
^\(\b.*\b\)\([^#]*\) → print(paste0("\1: ", \1) ) \2
But this highlights
samples <- rep(10, 5)*1000 ## steps determined by samples * thin
adaptive.ratio <- c(rep(c(1,0), 2), 0)
for the first replacement rather than what I want, which is to highlight only
print(paste0("samples: ", samples)) ## steps determined by samples * thin
I've tried escaping the # sign with #, adding a space between the two sets of parentheses, but that doesn't help.
I realize this is somehow related to the greedy nature of regexp matching, but I don't understand what am I doing wrong nor, as a result, how to fix it.