Question: Given the string `"http://compras.dados.gov.br/materiais/v1/materiais.html?pdm=08275/"`, I need to generate a regex filter so that it ignores the last char if it is an "/" .

I tried the following regex `"(http:////)?compras\\.dados\\.gov\\.br.*\\?.*(?<!//)"` as of [regexr.com/4om61](http://regexr.com/4om61), but it doesn´t work when I run in R as:

```
regex_exp_R   <- "(http:////)?compras\\.dados\\.gov\\.br.*\\?.*(?<!//)"
grep(regex_exp_R, "http://compras.dados.gov.br/materiais/v1/materiais.html?pdm=08275/", perl = T, value = T)

```

I need this to work in pure regex and grep function, without using any string R package.
Thank you.

**Simplified Case:**
After important contributions of you all, one last issue remains. 
Because I will use regex as an input in another friunction, the solution ***must work with pure regex and grep***.

The remaining point is a very basic one: given the strings "a1bc/" or "a1bc", the regex must return "a1bc". Building on suggestions I received, I tried

`grep(".*[^//]" ,"a1bc/", perl = T, value = T)`, but still get "a1bc/" instead of "a1bc". Any hints? Thank you.

Answer: 
You can use a negative look-behind at the end to ensure it doesn't end with the character you don't want (in this case, a `/`). The regex would then be:

```
.+(?<!\/)

```

You can view it here with your three input examples: <https://regex101.com/r/XB9f7K/1/>. If you only want it to match urls, then you would change the `.+` part at the beginning to your url regex.
How about trying `gsub("(.*?)/+$","\\1",s)`?