I have R objects that have domain names and IP addresses in them. For example.

```
11.22.44.55.test.url.com.localhost

```

I used regex in R to capture the IP addresses. My problem is that when there is no match the whole string gets matched or "outputed". This becomes a problem as I work on a very large dataset. I currently have the following using regex

```
sub("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*","\\1.\\2.\\3.\\4","11.22.44.55.test.url.com.localhost")

```

which gives me 11.22.44.55 

```
11.22.44.55

```

but if I were to have to following

```
sub("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*","\\1.\\2.\\3.\\4","11.22.44.test.url.com.localhost")

```

Then it gives me 

```
11.22.44.test.url.com.localhost

```

which is actually not correct. Wondering if there is any solution for this.