当原始字符串使用特殊字符的组合,例如不等式(< =&> =)时,如何将模式传递给compile()方法?
我如何获取我的re.compile函数以识别结合特殊字符(> =&< =)的不平等现象?它只能拿起相等的标志,我需要两个符号。
代码:
constraint_re = re.compile(r"(?P<prefix>['~','^','>=','<='])?(?P<major>\d+)(\.(?P<minor>(\d+|x)))?(\.(?P<patch>(\d+|x)))?(-.*)?")
testmatch = constraint_re.search("~0.0.2")
testmatch.group("prefix")
输出:
'~'
的测试代码
testmatch_1 = constraint_re.search("<=0.0.2")
testmatch_1.group("prefix")
&lt; =输出
'='
How do I get my re.compile function to identify inequalities that combine special characters ( >= & <=) ? It only picks up the equal sign and I need both symbols together.
Code:
constraint_re = re.compile(r"(?P<prefix>['~','^','>=','<='])?(?P<major>\d+)(\.(?P<minor>(\d+|x)))?(\.(?P<patch>(\d+|x)))?(-.*)?")
testmatch = constraint_re.search("~0.0.2")
testmatch.group("prefix")
Output:
'~'
Test code for <=
testmatch_1 = constraint_re.search("<=0.0.2")
testmatch_1.group("prefix")
Output
'='
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论