正则表达式:搜索介于1到99之间的任何数字,而不是0,但是是10,20排除。在python中

时间:2019-05-29 12:16:29

标签: python regex

我对此部分有疑问: [1-99] 它与我匹配,例如chr10,chr16,但不匹配chr20。 对于chr20,它仅返回chr2

****我想要1-99之间的任何数字。在数字的开头(例如05)不为零,但是我想除20,50之类的数字外……我尝试了\ d [^ 0] {1,2},但它也没有用。

有什么想法吗? 谢谢!

代码:

def is_bed(file):
  with open (file,"r+") as f:
        results = []
        for line in f:
            a = line.rstrip("\n")
            print(a)
            matches =re.findall(r"(chr)([1-99]{1,2}|[a-z]{1}|[A-Z]{1}\t([^0]\d+)\t([^0]\d+))",a)  
            print (matches)

输出:

chr20   36612318        36646196
[('chr', '2')
chr12   93569814        93583487
[('chr', '12')]

我需要获取所有数字。

0 个答案:

没有答案