如何在python中将正则表达式匹配的一部分作为变量? [英] How can I get part of regex match as a variable in python?
本文介绍了如何在python中将正则表达式匹配的一部分作为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Perl中可以执行这样的操作(我希望语法是正确的...):
In Perl it is possible to do something like this (I hope the syntax is right...):
$string =~ m/lalala(I want this part)lalala/;
$whatIWant = $1;
我想在Python中做同样的事情,并用$ 1之类的字符串来获取括号内的文本.
I want to do the same in Python and get the text inside the parenthesis in a string like $1.
推荐答案
请参阅:
这篇关于如何在python中将正则表达式匹配的一部分作为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文