So I'm trying to figure out how to format my function that grabs my ipaddress to basically just keep the numbers. My function is:
myIPaddress <- readLines("https://lnkd.in/drb3YQZV", warn = FALSE)
The variable is (with the numbers substituted with zeroes so as not to post my actual ip adress)
> myIPaddress
[1] "{\"ip\":\"000.00.000.00\"}"
I want it to be formatted so it just has
> myIPaddress
[1] "000.00.000.00"
I've tried a couple variations of gsub but am struggling. I'm trying to first get rid of everything in the beginning, so I have tried:
> myIPaddress <- readLines("https://lnkd.in/drb3YQZV", warn = FALSE) %>%
+ gsub(".*\\0",'')
Error in gsub(., ".*\\0", "") :
invalid regular expression '{"ip":"000.00.000.00"}', reason 'Invalid contents of {}'
In addition: Warning message:
In gsub(., ".*\\0", "") :
TRE pattern compilation error 'Invalid contents of {}'
So I think it's having a problem with the fact that some of the characters are in the brackets {}. So I found that I could use the perl=TRUE addition and then it just removed everything, as shown below.
> myIPaddress <- readLines("https://lnkd.in/drb3YQZV", warn = FALSE) %>%
+ gsub(".*\\1",'',perl=TRUE)
> myIPaddress
[1] ""
So doing it this way just completely removed the whole address. Any help would be appreciated