我需要一些帮助来声明正则表达式。我的输入如下:
this is a paragraph with<[1> in between</[1> and then there are cases ... where the<[99> number ranges from 1-100</[99>.
and there are many other lines in the txt files
with<[3> such tags </[3>
所需的输出是:
this is a paragraph with in between and then there are cases ... where the number ranges from 1-100.
and there are many other lines in the txt files
with such tags
我已经试过了:
#!/usr/bin/python
import os, sys, re, glob
for infile in glob.glob(os.path.join(os.getcwd(), '*.txt')):
for line in reader:
line2 = line.replace('<[1> ', '')
line = line2.replace('</[1> ', '')
line2 = line.replace('<[1>', '')
line = line2.replace('</[1>', '')
print line
我也尝试过此方法(但似乎我使用了错误的regex语法):
line2 = line.replace('<[*> ', '')
line = line2.replace('</[*> ', '')
line2 = line.replace('<[*>', '')
line = line2.replace('</[*>', '')
我不想replace
从1到99 进行硬编码。。。
4
接受的答案已经涵盖了您的问题并已解决。你还需要什么别的吗 ?
—
HamZa 2013年
结果应该是什么
—
utapyngo 2013年
where the<[99> number ranges from 1-100</[100>
?
它也应该删除
—
alvas 2013年
<...>
标签中的数字,所以输出应该是where the number rangers from 1-100 ?