Python从Perl到Python重新表达 [英] Python re expr from Perl to Python
问题描述
在Perl中,它是:
##示例:" Abc | def | ghi | jkl"
## - " abc ghi jkl"
##只收取第二根烟斗的文字(=剪切第一条文字
pipe)。
$ na = ~s / \ \ |(。*?)\ \ |(。*?)\ \ | / $ 2 / g;
## - 删除文本中的[和]
$ na = ~s / \ [// g;
$ na = ~s / \] // g;
#print" DEB:\" $ na\" \ n";
#输入字符串
na =" Abc | def | ghi | jkl [gugu]"
#输出
na =" abc ghi jkl gugu"
如何在Python中完成?
na = ~s / \ \ |(。*?)\ \ |(。*?)\ \ | /
2 / g;
## - 删除文本中的[和]
< blockquote> na = ~s / \ [// g;
In Perl, it was:
## Example: "Abc | def | ghi | jkl"
## -"Abc ghi jkl"
## Take only the text betewwn the 2nd pipe (=cut the text in the 1st
pipe).
$na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g;
## -- remove [ and ] in text
$na =~ s/\[//g;
$na =~ s/\]//g;
# print "DEB: \"$na\"\n";
# input string
na="Abc | def | ghi | jkl [gugu]"
# output
na="Abc ghi jkl gugu"
How is it done in Python?
na =~ s/\ \|(.*?)\ \|(.*?)\ \|/
2/g;
## -- remove [ and ] in text
na =~ s/\[//g;
这篇关于Python从Perl到Python重新表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!