Python Regular

http://www.runoob.com/python/python-reg-expressions.html

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import codecs
import os.path
import re

predefClassesFile = "F:\DL\labelImg\data\predefined_classes.txt"

labelHist = []
if os.path.exists(predefClassesFile) is True:
    with codecs.open(predefClassesFile, 'r', 'utf8') as f:
        for line in f:
            line = line.strip()
            if labelHist is None:
                labelHist = [line]
            else:
                labelHist.append(line)

strlist = []
for str in labelHist:
    pattern = re.compile(r'big')
 #   if  re.search(pattern,str):    #查找是否含有该pattern
    if  re.match(pattern,str):      #匹配
        strlist.append(str)
print strlist

你可能感兴趣的:(Python)