AlexC
AlexC

Reputation: 9661

How to use jQuery to extract a URL parameter from a string

i hat one task, and know i have to continue but have a bad experience with regexp ... :(

can somebody help me :

i need to take a sting from "domain url" with jquery :

This is the address name :

http://mydomain/Our-Company/default.aspx?txt=James D. Perrlo

I want to take with jquery la string after "?txt=" in this case "James D. Perrlo"

PS: This string always is ends of the url

Can somebody help me ?

Thanks !

Upvotes: 1

Views: 694

Answers (2)

karim79
karim79

Reputation: 342635

This small URL plugin lets you do this:

var url = $.url('http://allmarkedup.com/folder/dir/index.html?item=value');
url.attr('protocol'); // returns 'http'
url.attr('path'); // returns '/folder/dir/index.html'

https://github.com/allmarkedup/jQuery-URL-Parser

Upvotes: 3

casraf
casraf

Reputation: 21684

/.+\?(.[^&]+)/ should do the trick.

Upvotes: 0

Related Questions