帮助正则表达式从URL锚点中提取值

时间:2010-10-11 22:31:13

标签: regex django-urls

在Django URL模式中,采用此URL的正确方法是什么:

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

并创建变量:

access_token = 12345678910 | b1827b912847b81938747b91849-193867192305817 | EKWOGJhcinWIjWij8174-NgjRojb

expires_in = 0

我一直试图让这个工作,但无济于事......

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

1 个答案:

答案 0 :(得分:1)

试试这个:

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

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);

?>