Starting with the string -theta[0] * x[0] * x[4] -theta[1] * x[1], I'd like capture theta[.] and replace with exp(theta[.]) giving the final result as:
-exp(theta[0]) * x[0] * x[4] -exp(theta[1]) * x[1]
How do I accomplish this in R?
I tried the following to test by matching between as as follows:
p <- c("abba", "abcdab")
gsub("\\(a[^a]*a\\)", "|\\1|", p)
I expected the output to be something like
|abba|
|abcda|b
But the output is
[1] "abba" "abcdab"
What is the proper regex expression to achieve the desired result?
Thanks in advance.