简体   繁体   English

python re.sub()与?P

[英]python re.sub() with ?P

Can I use a variable from the first argument of re.sub (), to use it in the second argument? 我可以使用re.sub()第一个参数中的变量,在第二个参数中使用它吗? Let me explain with an example: 让我用一个例子来解释:

re.sub(r'(?P<id>>>>[0-9]+)', 'sometext(?P=id)sometext', self.text))

Can I use id variable in 'sometext(?P=id)sometext'? 我可以在'sometext(?P = id)sometext'中使用id变量吗? Actually, this code dont work, so i came here. 实际上,此代码不起作用,所以我来到了这里。

您可以按编号引用捕获组,例如第一个捕获组为\\1

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

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