Vous souhaitez récupérer la chaîne avant .html
et après la dernière apparition de %2F
. Vous pouvez utiliser l'expression régulière /%2F([^%]+?)(\.html$)/
. \.html$
correspond à la chaîne avant la dernière apparition; ([^%]+?)
partie correspond à la plus courte chaîne qui ne comprend pas %
et avant .html
qui est ce que vous voulez récupérer; %2F
exclut cette chaîne dans les correspondances.
var str = "http://platform.twitter.com/widgets/tweet_button.1329950604.html#_=1330013339435&count=none&hashtags=allstar&id=twitter-widget-10&lang=en&original_referer=http%3A%2F%2Fwww.nba.com%2Fpulse%2Fallstar%2F2012%2Findex.html&related=%40nba&size=m&text=Sprite%20Slam%20Dunk%20Contest%20is%20trending%20on%20NBA%20All-Star%20Pulse%20&url=http%3A%2F%2Fwww.nba.com%2Fpulse%2Fallstar%2F2012%2Ftopics%2Fspriteslamdunk.html"
var matches = str.match(/%2F([^%]+?)(\.html$)/)
matches
// => ["%2Fspriteslamdunk.html", "spriteslamdunk", ".html"]
matches[1] // What you want.
http://xkcd.com/208/ – talnicolas
Vous voulez faire la manipulation de chaînes de base ... pourquoi voudriez-vous impliquer jQuery? – Quentin