Boehmi
Boehmi

Reputation: 981

How do I make sure that RegEx returns false when a slash is at the end?

I'm trying to get a search pattern done so I get the video URL on certain portals. For one particular site I've been using this:

/www.website.net\/category\/[a-z-]*\/[a-z-]*\/[0-9a-z]*^[^\/]/

on www.website.net/category/topic/more/abcde/

in order to say 'the string matches' only if there isn't a slash after the abcde part. I now managed to do this, but even if the slash at the end is gone it doesn't return any matches. What did I do wrong?

EDIT:

I now settled for

/www.website.net\/category\/[a-z-]*\/[a-z-]*\/[0-9a-z]*[^\/]+$/ 

in order to only prevent the match if there is a slash, since the video URL at the back also has a string in the format /abcde-here-comes-video-name. Thanks!

Upvotes: 0

Views: 54

Answers (2)

Daniel Landau
Daniel Landau

Reputation: 2314

Near the end of your regex, you have "^[^/]". The first caret (^) shouldn't be there.

Upvotes: 2

alecxe
alecxe

Reputation: 473803

How about checking for the end of the string using $:

/www.website.net\/category\/[a-z-]*\/[a-z-]*\/[0-9a-z]*$/

Upvotes: 2

Related Questions