Saxman
Saxman

Reputation: 5089

jQuery and RegEx to extract a bit of information from URL Querystring

The query strings in my ASP.NET MVC are formatted like this: http://mysite.com/blog/tag/my-tag, instead of http://mysite.com/blog/?tag=my-tag, I need to extract the "my-tag" bit out of the URL, how could I accomplish that with jQuery on document loaded?

Upvotes: 1

Views: 221

Answers (2)

Jibran
Jibran

Reputation: 930

Try This:

document.location.toString().match('.*/(.*)$')[1]

Upvotes: 0

lonesomeday
lonesomeday

Reputation: 237975

No need to use jQuery for that:

var tag = window.location.href.split('/').pop();

Upvotes: 2

Related Questions