Python Forum

Full Version: Extract a List element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have this code:
cl = re.findall(r'[claim number]+[0-9]+', claim_num_50)
It gives me back a list
Output:
[' 19', ' 0333', ' number 63108316972', ' claim number 193137164', ' 21', ' 871', ' 1291', ' 86', ' 670', ' 2294', ' c 83', ' 546']
But I only want Claim Number from the output, how do I extract it?
Quote:'claim number 193137164'


I have tried
 cl2 = ''.join(cl)
    cl3 = cl2.split('claim',1)[1][0:30]
    print(cl3)
Output
Output:
number 193137164 21 871 1291
But I think it's a long way and doesn't really give me what I want.
Post example of input text before messing with it.
Try this:
r'claim number \d{9}'

\d{9} == exact 9 numbers

To allow a range, you can use a comma:
\d{4,9} == 4-9 numbers
Thank you, it worked Big Grin

(Apr-29-2019, 02:53 PM)DeaD_EyE Wrote: [ -> ]Try this:
r'claim number \d{9}'

\d{9} == exact 9 numbers

To allow a range, you can use a comma:
\d{4,9} == 4-9 numbers
What if I want to any number after a word claim that's \d{9}?

(Apr-29-2019, 02:53 PM)DeaD_EyE Wrote: [ -> ]Try this:
r'claim number \d{9}'

\d{9} == exact 9 numbers

To allow a range, you can use a comma:
\d{4,9} == 4-9 numbers