[Tutor] Python Regular Expressions (Re.sub) Function
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.mwa...@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/> -- |Rawzeea NLKPP | VE11-Nairobi | 20002254-MADIZ| 00 | 00 |Regular Scheme B | 15-JAN-2019 To 31-DEC-2019 | No | || | 3648 | 18-FEB-2020 | Yes | 03 | .00 USD | 0.00 USD | Leased Commercially | 00.00 KES| No | || | R-9-01 | 00.00% |0023.28 KES |000.18 USD | | 1.0 | 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 | |
[Tutor] My problem in simple terms
Hi there , Earlier i had sent an email on how to use re.sub function to eliminate square brackets. I have simplified the statements. Attached txt file named unon.Txt has the data im extracting from. The file named code.txt has the codes I'm using to extract the data.The regular expression works fine but my output has too many square brackets. How do i do away with them thanks. Regards, Kanja Edward. P.O.BOX 1203-00300, NAIROBI. *+254720724793* www.linkedin.com/in/edward-kanja-bba16a106 <http://linkeldin/> -- |Rawzeea NLKPP | VE11-Nairobi | 20002254-MADIZ| 00 | 00 |Regular Scheme B | 15-JAN-2019 To 31-DEC-2019 | No | || | 3648 | 18-FEB-2020 | Yes | 03 | .00 USD | 0.00 USD | Leased Commercially | 00.00 KES| No | || | R-9-01 | 00.00% |0023.28 KES |000.18 USD | | 1.0 | 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 | | | hous...@weekly.com | --- -- |Pattly MUNIIZ | TX00-Nairobi | 2006-KZAU | 00 | 00 |Regular Scheme B | 05-JAN-2010 To 01-JAN-2019 | No | || | 1007 | 07-DEC-2019 | No | 00 | .00 USD | 0.00 USD | Leased Commercially | 00.00 KES| No | || | K-3-10 | 00.00% |.25 KES |.60 USD | | 1.0 | 0.00| 0.00
Re: [Tutor] My problem in simple terms
Greetings, I'm referring to my question i sent earlier, kindly if you have a hint on how i can solve my problem i will really appreciate. After running regular expressions using python my output has lot of square brackets i.e. [][][][][][][][][]. How do i substitute this with empty string so as to have a clear output which i will latter export to an excel file. Thanks a lot. Regards, Kanja Edward. P.O.BOX 1203-00300, NAIROBI. *+254720724793* www.linkedin.com/in/edward-kanja-bba16a106 <http://linkeldin/> On Mon, Mar 4, 2019 at 2:44 PM Edward Kanja wrote: > Hi there , > Earlier i had sent an email on how to use re.sub function to eliminate > square brackets. I have simplified the statements. Attached txt file named > unon.Txt has the data im extracting from. The file named code.txt has the > codes I'm using to extract the data.The regular expression works fine but > my output has too many square brackets. How do i do away with them thanks. > > > > Regards, > Kanja Edward. > P.O.BOX 1203-00300, > NAIROBI. > *+254720724793* > www.linkedin.com/in/edward-kanja-bba16a106 <http://linkeldin/> > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor