Simeon Kolev
Simeon Kolev

Reputation: 646

Regex help in javascript

I need to use regex to extract strings delimited by '/'. I need to extract till the second slash:

for example form the following string:

word1 word2/word3 word4 word5/word6/word7 word8 word9

The following string:

word1 word2/word3 word4 word5

Upvotes: 0

Views: 68

Answers (4)

schnill
schnill

Reputation: 955

hey try this without using regex`

'http://domain.com/some_path/bla-bla/bla-bla'.split("/",4).join("/");

it'll give what u want.

Upvotes: 2

Srb1313711
Srb1313711

Reputation: 2047

Try this:

\w+:(\/)\1(\w+)\.\w+\1\w+\1

Upvotes: 2

Barmar
Barmar

Reputation: 780688

This should do it:

/^[^\/]*\/\/[^\/]*\/[^\/]*\//

Upvotes: 2

falsetru
falsetru

Reputation: 368904

Try following code.

'http://domain.com/some_path/bla-bla/bla-bla'.match(/(https?|ftp):\/\/([^/]+\/){1,2}/)[0]
=> "http://domain.com/some_path/"

Upvotes: 2

Related Questions