简体   繁体   English

用于在url中转义路径分隔符的正则表达式

[英]Regex for escaping path separator in url

I have a url pattern: "somepath/email/". 我有一个网址模式:“somepath / email /”。 I don't want to write a regex for matching email instead I want anything which isn't a path separator to match email. 我不想写匹配电子邮件的正则表达式,而是我想要任何不是路径分隔符来匹配电子邮件的东西。

Please suggest a regex for this. 请为此建议正则表达式。 I am using Python and the url is for a Django application, So any library function will also be helpful but I will prefer a regex. 我正在使用Python,而url是用于Django应用程序,所以任何库函数也都会有用,但我更喜欢正则表达式。

The regex [^/\\\\]+ is a negative character class with a + quantifier and matches any number of characters that are not a / or \\\\ 正则表达式[^/\\\\]+是带有+量词的负字符类,并且匹配任何数量不是/\\\\的字符

Code sample: 代码示例:

match = re.search("[^/\\]+", subject)
if match:
    result = match.group()
else:
    result = ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM