Python从Perl到Python重新表达 [英] Python re expr from Perl to Python

查看:54
本文介绍了Python从Perl到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆