Arash Donsali Kapoor
Arash Donsali Kapoor

Reputation: 184

Get regex to stop at a certain character, but include that character in match

Right now, this regex matches something and stops at a slash ( / ), but I need it to stop at the slash and include the slash. Or in other words stop at whatever character is after the slash. But, I don't know what that charcter is.

Any ideas on how to do this?

Here is the regex:

   (?:https?:\/\/|www)[^\/]*

Upvotes: 1

Views: 2882

Answers (2)

Oussama Jilal
Oussama Jilal

Reputation: 7739

You can do it in 2 ways :

(?:https?:\/\/|www)[^\/]*\/

or this :

(?:https?:\/\/|www).*?\/

Edit:

To stop at the lasts slash use this :

(?:https?:\/\/|www)[^\/]+(?:\S*?\/)*

Upvotes: 2

mellamokb
mellamokb

Reputation: 56769

Add the slash as part of your regular expression:

(?:https?:\/\/|www)[^\/]*\/
                         ^^ add this

Upvotes: 0

Related Questions