[Tutor] Python Regular Expressions (Re.sub) Function
Edward Kanja
edwardkanja254 at gmail.com
Mon Mar 4 03:04:15 EST 2019
Hi there,
Hope this finds you well, I'm working on a simple project to analyse data
using
regular expressions. I have successfully worked on a regular expression
pattern
that extracts data from my txt file. Unfortunately after i extract the data
my output has too much of square brackets and by so doing the output cant
be well exported in a csv file. I have worked on an idea of Re.sub function
where i'm trying to replace all square brackets in my output with an empty
string.
Below are images of what i have been working on.
Explanations of the attachments and images named as follows:
*1. mydata in txtfile. *This images shows how my data looks in the txt file
although
i have also attached the real txt file with the actual data below.
*2. code for the output. *This image shows the regular expression that is
well extracting the data from my txt file.
3. *my output. *This image shows the out after i ran my code . it shows the
square brackets that are in my output and ones i need to do away with.
4.*tryone code. *This image shows my first try using re.sub to eliminate
the square brackets.
*5. tryone output.*This images shows the output i had after running the
code in the image named tryone code.
*6. try two code:*This image shows my second try using re.sub to eliminate
the square brackets.
*7.trytwo output.*This images shows the output i had after running the code
in the image named trytwo code.
*8.try four code.*This image shows my fourth try using re.sub to eliminate
the square brackets.
*9.try four output.* This images shows the output i had after running the
code in the image named tryfour code.
*10.try five code.*This image shows my number five try using re.sub to
eliminate the square brackets
*11.* *try five output.*This images shows the output i had after running
the code in the image named tryfive code.
*12.line five name code regex.*This image shows the full code for the name
regular expression with the re.sub function for the code
in the image named try five code.
*13.try six code.*This image shows my sixth try using re.sub to eliminate
the square brackets
*14. try six output.*This images shows the output i had after running the
code in the image named tryfsix code
*15.try six full name code.*This image shows the full code for the name
regular expression with the re.sub function for the code
in the image named try six code.
*16. unon.TXT. *This is the txt file that has the data i am extracting.
Kindly assist and kindly copy my work email ( edward.mwangi at un.org ) when
replying .
Thanks alot.
Regards,
Kanja Edward.
P.O.BOX 1203-00300,
NAIROBI.
*+254720724793*
www.linkedin.com/in/edward-kanja-bba16a106
<http://linkeldin/>
-------------- next part --------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Rawzeea NLKPP | VE11-Nairobi | 20002254-MADIZ | 00 | 00 |Regular Scheme B | 15-JAN-2019 To 31-DEC-2019 | No |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 11113648 | 18-FEB-2020 | Yes | 03 | 0000.00 USD | 0.00 USD | Leased Commercially | 000000.00 KES | No |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| R-9-01 | 00.00% |0023.28 KES |000.18 USD | | 1.00000 | 0.00 | 0.00 | No | 10-JAN-2019 To 31-DEC-2019 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Valid From: 17-Jan-2017 | Warwass Center |
| Warwass Center | UK-8 |
| | UK Avenue |
| Nairobi---Kenya | |
| | Nairobi--00100-Kenya |
| | 0207690606 |
| | housert at weekly.com |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Pattly MUNIIZ | TX00-Nairobi | 20000006-KZAU | 00 | 00 |Regular Scheme B | 05-JAN-2010 To 01-JAN-2019 | No |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 10000007 | 07-DEC-2019 | No | 00 | 0000.00 USD | 0.00 USD | Leased Commercially | 000000.00 KES | No |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| K-3-10 | 00.00% |0000.25 KES |0000.60 USD | | 1.00000 | 0.00 | 0.00 | No | 01-JAN-2019 To 01-JAN-2000 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Valid From: 65-Feb-2010 | Kuthat Skuh |
| 98 Runka road | 98 |
| | Runka Road |
| Nairobi---Kenya | |
| | Nairobi--00200-Kenya |
| | |
| | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
More information about the Tutor
mailing list