1

I don't want to get everything after slash or before.

I want to check if last slash is present or not.

For Example

http://google.com/   --no
http://google.com/abc   --no
http://google.com/abc?c=1 --no
http://google.com/abc/ --yes
http://google.com/abc/?c=1 --yes
0

1 Answer 1

1

You can use this regex:

/https?:\/\/[^\/]+\/.*?\/(?=\?|$)/igm

RegEx Demo

Sign up to request clarification or add additional context in comments.

2 Comments

i modified question a little bit, sorry missed something crucial
i'm trying to make pathname based array. So i wan't path / to represent root. But i also want /a, /a/,/a?...,and /a/?... to be the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.