bsod99 bsod99 - 1 year ago 84
Javascript Question

Regex - strip out text between first and second forward slashes

I've almost got this regex working but am having trouble with the leading forward slash - can anyone see where I'm going wrong with this? I just want to extract the first string, "projects" in this example here ->

Answer Source

The easiest way is to split string using forward slash

var firstString = url.split('/')[1];

and you will have first string, but if you want to extract using regext than this will do, just remember don't add global parameter in your regex.


I hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download