I am facing a challenge in extracting both the product name and price from the given data. The desired result, which includes both the product name and price, is not on the same line. How can I include the line that comes before the price as well?
Here is a sample structure of a product from a receipt:
RETAIL
UPRICE QTY TOTAL
ILLUSTRATION BOARD 15X20 (1/4 SIZE ) BY
1276
12.50 1.0 12.50
MONGOL PENCIL 1,2,3 PC
434
6.50 1.0 6.50
MS 300 (MGK) PERMANENT MARKER
1470
3.75 1.0 3.75
HBW White Glue 40 grans
1690
10.00 1.0 10.00
COLOR PEN 8 COLORS (VARIOUS BRAND)
1930
16.50 1.0 16.50
KS /CREATION CONSTRUCTION PAPER (105)
3503
23.00 1.0 23.00
I have attempted to use the following regex to solve the issue, but the result only displays the price without including the product name. The 'result' variable contains data similar to the sample provided above.
TypeScript file code snippet:
this.result = {
merchant: text.split("\n")[0],
product: text.split("\n").filter(t => t.match(/([\w\s]+)(\d+\.\d{2})/)
};
HTML file code snippet:
<ion-card *ngIf="result">
<ion-card-content>
<p>Results:</p>
<ion-item>
<ion-label>Merchant</ion-label>
<ion-input type="text" value="{{result.merchant}}"></ion-input>
</ion-item>
<ion-item *ngFor="let product of result.product; let i = index">
<ion-label>Product #{{i+1}}</ion-label>
<ion-input type="text" value="{{product}}"></ion-input>
</ion-item>
</ion-card-content>
</ion-card>