[英]Regex matching alphanumeric with special characters
I am trying to form an url in Django url pattern . 我正在尝试在Django URL模式中形成一个URL。
url(r'^reports/(?P<bu>\w+|\W)/$', \
LrsReportView.as_view(), name="elearning.lrsreports.region"),
The bu can be a string or string alphanumeric or alphanumeric with special character (except /) bu可以是字符串或字符串,字母数字或带有特殊字符的字母数字(/除外)
But the above url is showing error for 但是上面的URL显示错误
NoReverseMatch: Reverse for 'elearning.lrsreports.region' with arguments '(u'Lawn&Garden',)' and keyword arguments '{}' not found.
From the error I understood is this regex is not accepting the string having special character 从我理解的错误是这个正则表达式不接受具有特殊字符的字符串
Please help me out what might wrong here . 请帮我解决这里可能出什么问题。
Your current RegEx will match: 您当前的RegEx将匹配:
OR 要么
You probably need something more like: 您可能需要更多类似的东西:
(?P<bu>[\w-]+)
This will match letters, numbers, underscore and hyphens. 这将匹配字母,数字,下划线和连字符。 Add any other special characters you want as well (inside the square brackets).
还要添加其他所需的特殊字符(在方括号内)。 Remeber certain characters need escaping with
\\
before them. 记住某些字符需要在它们之前使用
\\
进行转义。
Try this- 尝试这个-
/^(?=. [az])(?=. [AZ])(?=. \\d)(?=. (_|[^\\w])).+$/ / ^(?=。 [az])(?=。 [AZ])(?=。 \\ d)(?=。 (_ | [^ \\ w]))。+ $ /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.