I am currently trying to figure out how to use regex in order to clean up my textual data in R. I wonder where I could find an easy tutorial for it? I have been looking a bit online, but when I try something out on regex101 I hardly ever find matches. And if I do, within R, nothing changes. Consider this example
Before <- "ACEMOGLU, D., ROBINSON, J., (2012) WHY NATIONS FAIL, (3)"
After <- "ACEMOGLU, D., ROBINSON, J., 2012, WHY NATIONS FAIL, (3)"
> Aftergsub <- gsub("\\([\\d][\\d][\\d][\\d]\\)", "new", "ACEMOGLU, D., ROBINSON, J., (2012) WHY NATIONS FAIL, (3)")
> print(Aftergsub)
[1] "ACEMOGLU, D., ROBINSON, J., (2012) WHY NATIONS FAIL, (3)"
>
Of course the "new" should be an expression that would make Before look like After. But I don't even get to change Before into anything else, based on my pattern.
In other words, how do I only change a ")" to a "," if it has been preceded by 4 digits? Thanks!