Reputation: 646
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
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
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