import re test_input = """12/23 12/23 2442733B5LYRNY9N6 MCDONALD'S F10271 SAN ANTONIO TX $9.20 12/23 12/23 2442733B5MHE8GGGX H-E-B #211 SAN ANTONIO TX $43.22 12/23 12/23 2469216B533EZLVHW AMZN Mktp US*481GX7TP3 Amzn.com/bill WA $42.95 12/23 12/23 2469216B53357XENW AMZN Mktp US*V92QS2DV3 Amzn.com/bill WA $8.65 12/26 12/26 2442733B9LYPP7BL5 TA #147 SAN ANTONIO FA SAN ANTONIO TX $17.84 12/26 12/26 2469216B8353SDFYB LOWES #01645* SAN ANTONIO TX $66.02 12/28 12/28 2449215BAMNMZ7HX8 ZAGG - ECOM 800-700-9244 UT $28.13 12/29 12/29 2427539BBS66GHFEA MOTOROLA ACCESSORIES 312-3104753 IL $54.11 12/29 12/29 2469216BB2XVL8LR4 AMZN Mktp US*6P5LY8AB3 Amzn.com/bill WA $8.65 12/30 12/30 2423168BDRBGNY35K TACO BELL #34966 SAN ANTONIO TX $11.46 12/31 12/31 2401339QH000YV7Z8 030 TORCHYS LINCOLN HEIGH SAN ANTONIO TX $14.82 12/31 12/31 2413746QHEJBM10FG OFFICEMAX/DEPOT 6518 SAN ANTONIO TX $2.53 01/01 01/01 2469216QJ30NNQNMF JACK IN THE BOX 0814 SAN ANTONIO TX $12.64 01/02 01/02 2403596QJJEENJ6SR AMERICAN AIR0012104071805 FORT WORTH TX SUPERNAW/LOREN SAN ANTONIO FORT WORTH FORT WORTH KANSAS CITY KANSAS CITY FORT WORTH $417.19 01/03 01/03 2423168QL2LRJE74A PETSMART # 0209 SAN ANTONIO TX $25.43 01/03 01/03 2469216QL31XRPYQ1 MICHAELS STORES 9815 SAN ANTONIO TX $8.65 01/04 01/04 2443106QLLQNNHNF5 MOTOROLA MOBILITY LLC 800-734-5870 IL $365.46 01/05 01/05 2494300QNRQEK367W TGI FRIDAYS #60843 DALLAS TX $30.39 01/09 01/09 2442733QTLYRQ84DP MCDONALD'S F10271 SAN ANTONIO TX $10.34 01/09 01/09 2449215QTLWH84S2A UBER TRIP HELP.UBER.COM CA $45.55 01/11 01/11 2413746QW2XGES755 CHURCHS CHICKEN 372 SAN ANTONIO TX $11.36 01/12 01/12 7498750QW00JGK78H Gamefound Wroclaw PL $41.00 01/15 01/15 2479338QZ005YPHG8 Store 855-8254275 TX $13.85 01/19 01/19 2449813D50W183V9L CAPPARELLI`S ITALIAN FOOD SAN ANTONIO TX $22.38 01/19 01/19 2405522D4RDQ512HV MINI FOOD MART SAN ANTONIO TX $41.23 01/19 01/19 2443106D4BM1GXHLX PETCO 1444 SAN ANTONIO TX $38.42 01/19 01/19 2449215D3MLF5GWJE ADOBE INC. 408-536-6000 CA $43.29 01/20 01/20 2442733D4MHDPS4JS H-E-B #026 SAN ANTONIO TX $49.69 01/20 01/20 2444500D5EJ00GWHY ARBY'S 8712 SAN ANTONIO TX $12.86 01/21 01/21 2401134D5000RZNY4 SP EKSTER HTTPSWWW.EKST NY $45.48 01/21 01/21 2423168D6RBGHKVRW TACO BELL #734966 928-681-3344 TX $6.92 01/21 01/21 2442733D5MHDF7722 H-E-B #026 SAN ANTONIO TX $50.38 01/21 01/21 2449216D5000HD257 SP DANGO PRODUCTS HTTPSDANGOPRO CA $100.29 01/22 01/22 2469216D6364PKY52 Amazon.com*R83XX98A1 Amzn.com/bill WA $108.24 01/23 01/23 Interest Charge on Purchases $330.06 01/23 01/23 Interest Charge on Cash Advances $0.00 01/23 01/23 Interest Charge on Balance Transfers $0.00""" pattern = re.compile("([01]\\d\/[0-3]\\d\\s){2}(\\d[A-Za-z0-9]+\\s)?(.*?(?=\\$[\\d\\.]+))\\$([\\d\\.]+)", flags=re.IGNORECASE|re.DOTALL) matches = re.findall(pattern, test_input) parsed = [] [print(match) for match in matches] for match in matches: transaction_date = match[0].strip() reference_number = match[1].strip() description = match[2].strip().replace("\n", "; ") amount = match[3].strip() parsed.append([transaction_date, reference_number, description, amount]) [print(transaction) for transaction in parsed]
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |