Pyparsing: extract variable length, variable content, variable whitespace substring

前端 未结 3 1654
误落风尘
误落风尘 2020-12-11 10:58

I need to extract Gleason scores from a flat file of prostatectomy final diagnostic write-ups. These scores always have the word Gleason and two numbers that add up to anoth

3条回答
  •  庸人自扰
    2020-12-11 11:27

    gleason = re.compile("gleason\d+\d=\d")
    scores = set()
    for record in records:
        for line in record.lower().split("\n"):
            if "gleason" in line:
                scores.add(gleason.match(line.replace(" ", "")).group(0)[7:])
    

    Or something

提交回复
热议问题