【问题标题】:Regex for match url in DjangoDjango中匹配url的正则表达式
【发布时间】:2020-10-11 21:10:59
【问题描述】:

我正在尝试将此 url 与 django/python 中的正则表达式匹配(旧的 liferay url)

http://127.0.0.1:8080/documents/34105/35593/prova+(1)+(1).jpg/da459266-ab36-faf1-726d-fc989385b0bd

但我无法解码文件名...

这是我使用的正则表达式:

documents/(?P<repo>[0-9]{5,10})/(?P<folder>[0-9]{5,10})/(?P<filename>[])/(?P<uuid>[\w-]+)

这是 Pythex link

【问题讨论】:

    标签: python django regex


    【解决方案1】:

    随便用

    documents/(?P<repo>\d+)/(?P<folder>\d+)/(?P<filename>[^/]+)/(?P<uuid>[^/]+)
    

    proof

    说明

    --------------------------------------------------------------------------------
      documents/               'documents/'
    --------------------------------------------------------------------------------
      (?P<repo>                        group and capture to (?P=repo):
    --------------------------------------------------------------------------------
        \d+                      digits (0-9) (1 or more times (matching
                                 the most amount possible))
    --------------------------------------------------------------------------------
      )                        end of (?P=repo)
    --------------------------------------------------------------------------------
      /                        '/'
    --------------------------------------------------------------------------------
      (?P<folder>               group and capture to (?P=folder):
    --------------------------------------------------------------------------------
        \d+                      digits (0-9) (1 or more times (matching
                                 the most amount possible))
    --------------------------------------------------------------------------------
      )                        end of (?P=folder)
    --------------------------------------------------------------------------------
      /                        '/'
    --------------------------------------------------------------------------------
      (?P<filename>             group and capture to (?P=filename):
    --------------------------------------------------------------------------------
        [^/]+                    any character except: '/' (1 or more
                                 times (matching the most amount
                                 possible))
    --------------------------------------------------------------------------------
      )                        end of (?P=filename)
    --------------------------------------------------------------------------------
      /                        '/'
    --------------------------------------------------------------------------------
      (?P<uuid>                  group and capture to (?P=uuid):
    --------------------------------------------------------------------------------
        [^/]+                    any character except: '/' (1 or more
                                 times (matching the most amount
                                 possible))
    --------------------------------------------------------------------------------
      )                        end of (?P=uuid)
    

    【讨论】:

    • 谢谢!太完美了!
    猜你喜欢
    • 2011-08-17
    • 2017-09-12
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    相关资源
    最近更新 更多