开发者

Help with regex to extract value from URL anchor

开发者 https://www.devze.com 2023-01-19 19:24 出处:网络
In Django URL patterns, what\'s the proper way to take this URL: http://example/i/fb/#access_token=12345678910|b1827b912847b81938747b91849-193867192305817|EKWOGJhcinWIjWij8174-NgjRojb&expires_in=

In Django URL patterns, what's the proper way to take this URL:

http://example/i/fb/#access_token=12345678910|b1827b912847b81938747b91849-193867192305817|EKWOGJhcinWIjWij8174-NgjRojb&expires_in=0

And create variables:

access_token = 12345678910|b1827b912847b81938747b91849开发者_如何学C-193867192305817|EKWOGJhcinWIjWij8174-NgjRojb

expires_in = 0

I've been trying to get this to work, but to no avail...

url(r'^fb/(?P([^&]+)(?:&expires=(.*))?/?$, 'app.views.test_url', name="test_url"),


Try this:

'[#?&]?([a-z_]+)=([0-9A-Za-z|\-]+)'

Example application in PHP:

<?php

    $url = "http://example/i/fb/#access_token=12345678910|b1827b912847b81938747b91849-193867192305817|EKWOGJhcinWIjWij8174-NgjRojb&expires_in=0";
    preg_match_all("%[#?&]?([a-z_]+)=([0-9A-Za-z|\-]+)%", $url, $matches, PREG_SET_ORDER);

    print_r($matches);

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号