1

I have a string

a='S
LINC             SHORT LEGAL                                   TITLE NUMBER
0037 471 661     1720278;16;21                                 172 211 342

LEGAL DESCRIPTION
PLAN 1720278  
BLOCK 16  
LOT 21  
EXCEPTING THEREOUT ALL MINES AND MINERALS  

ESTATE: FEE SIMPLE  
ATS REFERENCE: 4;24;54;2;SW

MUNICIPALITY: CITY OF EDMONTON

REFERENCE NUMBER: 172 023 641 +71

---------------------------------------------------------------------------- 
----
                     REGISTERED OWNER(S)
REGISTRATION    DATE(DMY)  DOCUMENT TYPE      VALUE           CONSIDERATION
----------------------------------------------------------------------------- 
---

172 211 342    15/08/2017                      $610,000        CASH & MTGE'

Need to extract values below document type, value and consideration and output in an array like ['','$610,000','CASH & MTGE'] I tried using findall(r'(?<!\S)(?:[$]\S+|[^$\d]+)\b', a). But I could only get ['$610,000','CASH & MTGE'] and no value for document type since it is empty.

1 Answer 1

0

From what I understood, you would like to return an Array with the values $610,000 CASH & MTGE' from the string right?

Assuming the required string value would remain in the end, we can leverage the splitlines function. Then, use len(a)-1 to fetch the required string something like this:

>>> a='''S
LINC             SHORT LEGAL                                   TITLE NUMBER
0037 471 661     1720278;16;21                                 172 211 342

LEGAL DESCRIPTION
PLAN 1720278  
BLOCK 16  
LOT 21  
EXCEPTING THEREOUT ALL MINES AND MINERALS  

ESTATE: FEE SIMPLE  
ATS REFERENCE: 4;24;54;2;SW

MUNICIPALITY: CITY OF EDMONTON

REFERENCE NUMBER: 172 023 641 +71

---------------------------------------------------------------------------- 
----
                     REGISTERED OWNER(S)
REGISTRATION    DATE(DMY)  DOCUMENT TYPE      VALUE           CONSIDERATION
----------------------------------------------------------------------------- 
---

172 211 342    15/08/2017                      $610,000        CASH & MTGE'''

>>> b=a.splitlines()
>>> req_line = b[len(b)-1]
>>> print(req_line)
Sign up to request clarification or add additional context in comments.

3 Comments

The above solution prints entire row in the last line as string. Instead is it possible to just get only last 3 field values in an array. Please not if there is empty value for a field, it should also be included too.
Well we can call split() function without arguments on req_line to return an array of fields that have values however if you need the empty columns as well, we need to probe the array values for their supposed location, say, if 'CASH' column will exist at all times, we can check if index 1 on the array has len > 0 and so on.
Is there any way to get empty strings into an array provided the column has any empty values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.