您的位置:首页 > 编程语言 > Python开发

Python 正则表达式验证URN

2014-10-15 09:43 771 查看
1. Check whether a string consists entirely of a valid URN
Match:
(?x)\Zurn:
# Namespace Identifier
[a-zA-Z0-9][a-zA-Z0-9-]{0,31}:
# Namespace Speficic String
[a-zA-Z0-9()+,\-.:=@;$_!*'%/?#]+
\Z

Result:
urn:nihao:nihao

2. Find a URN in a larger body of text
Match:
(?x)\burn:
# Namespace Identifier
[a-zA-Z0-9][a-zA-Z0-9-]{0,31}:
# Namespace Speficic String
[a-zA-Z0-9()+,\-.:=@;$_!*'%/?#]+

Result:
urn:nihao:nihao urn:nihao:good

3. Find a URN in a larger body of text, assuming that punctuation at the end of the URN
if part of the (English) text in which the URN is quoted rather than part of the URN itself
(?x)\burn:
# Namespace Identifier
[a-zA-Z0-9][a-zA-Z0-9-]{0,31}:
# Namespace Speficic String
[a-zA-Z0-9()+,\-.:=@;$_!*'%/?#]*[a-zA-Z0-9+=@$/]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: