I have a model formula (as string) and want to extract the value for a specific argument, id in my case. Now I have found a way that returns the string without the needed string value. I want exactly the opposite, I only want the string value that is missing in my result:
xx <- "gee(formula = breaks ~ tension, id = wool, data = warpbreaks)"
sub("(?=(id=|id =))([a-zA-Z].*)(?=,)", "\\1", xx, perl =T)
#> [1] "gee(formula = breaks ~ tension, id =, data = warpbreaks)"
wool is missing in the return value, but I only want to have wool as resulting string... Can anyone help me finding the correct regex pattern?
sub(".*id ?= ?(.*?),.*", "\\1", xx). You need to match the whole string.