Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex exclude slash character

Tags:

regex

url

I have the following (dummy) strings, that in reality are part of URLs:

methods/english
methods/english/dummy

I want my regex to exclude strings that have a slash after english. So the second string should not match the regex.

I tried this regex:

/methods/.*/[^/]

So that it excludes the slash character.

But with this logic it still matches with methods/english/dummy. I can't figure out why.

like image 457
Rosalie Haverkort Avatar asked Dec 09 '25 08:12

Rosalie Haverkort


1 Answers

You can use

^methods/[^/]+$

See the regex demo.

Details:

  • ^ - start of string
  • methods/ - a literal string
  • [^/]+ - one or more chars other than /
  • $ - end of string.
like image 169
Wiktor Stribiżew Avatar answered Dec 12 '25 01:12

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!