Question: I have a working chunk of regex, but I cannot get it to work in R. (Using <https://regex101.com/> to verify the regex works.)

I have this string:

```
pbb-nae-49/N2-A.N49AV048.SUP-DAMP

```

I need everything after the last period, which can be basically any characters (but I don't think spaces will ever exist after the last period). I have this which works in getting the string as a group:

```
\.([-0-9a-zA-Z\s]+\z)

```

And I also have this, which works a little differently (I am unsure which one will provide me better results with real data after testing):

```
[\w\d\/\.-]+\.([\w-]+)

```

Neither of these lines work to extract the strings in R:

```
tester = "pbb-nae-49/N2-A.N49AV048.SUP-DAMP"
gsub("[\\w\\d\\/\\.-]+\\.([\\w-]+)","POOP",tester) #returns original string
gsub("\\.([-0-9a-zA-Z\\s]+\\z)","POOP",tester) #returns original string

```

Any ideas how to fix this? Or what I am missing?

Answer: 
You can get this with

```
sub(".*\\.(.*)", "\\1", S)

```
Or another option is `str_match`

```
library(stringr)
str_match(tester, ".*\\.([^.]+$)")[,2]
#[1] "SUP-DAMP"

```

---

Or using the `base R` `sub` where we match the characters (`.*`) followed by a dot (`\\.`) and capture one or more characters that are not a dot (`[^.]+`) until the end (`$`) of the string and replace it with the backreference of that capture group (`\\1`)

```
sub(".*\\.([^.]+)", "\\1", tester)

```