Regular Expression

Pippo adm2303.2304 at gmail.com
Sun Apr 12 18:49:11 EDT 2015


I have a text as follows:

"#D{#C[Health] #P[Information] - 
means any information, including #ST[genetic information],
whether #C[oral | (recorded in (any form | medium))], that 
(1)#C[Is created or received by] a 
#A[health care provider | health plan | public health authority | employer | life insurer | school | university | or health care clearinghouse];  
(2)#C[Relates to] #C[the past, present, or future physical | mental health | condition of an individual] | 
#C[the provision of health care to an individual] | 
#C[the past, present, or future payment for the provision of health care to an individual].}"

I want to get all elements that start with #C and are []  and put it in an array. For example #C[Health], I try with regex but it doesn't work:

import re
import tkinter.filedialog
import readfile



j = 0

text = [ ]


content = readfile.pattread()

while j < len(content):

    constraint = re.compile(r'(#C\[\w*\]'))
    result = constraint.search(content[j],re.MULTILINE)
    text.append(result)
    print(text)
    j = j+1



More information about the Python-list mailing list