Regular Expression

MRAB python at mrabarnett.plus.com
Mon Apr 13 01:28:22 CEST 2015


On 2015-04-12 23:49, Pippo wrote:
> 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:
>
"... it doesn't work"? In what way doesn't it work?

> import re
> import tkinter.filedialog
> import readfile
>
>
>
> j = 0
>
> text = [ ]
>
>
> content = readfile.pattread()
>
> while j < len(content):
>
There's a syntax error here:

>      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