0
votes

I'm trying to regex all items from an invoice (name, unit price, total, VAT, etc.). Managed to get all the information regarding digits, but biggest problem si to extract the item descriptions as sometimes it's on two separate lines. This is what I need to regex

1 Agrafe metalice Eco, rotunjite, 33 mm, 50 buc/cutie buc. 30.00 0,76 22,80 4,33
 
 
(SOBO604)
 
2 Banda corectoare DONAU Mouse, 5 mm x 8 m, orizontala, buc. 5.00 4,83 24,15 4,59
 
 
blister (7635001PL-99)
 
 
3 Biblioraft plastifiat OFFICE Products, 5 cm, colturi buc. 75.00 5,08 381,00 72,39
 
 
metalice, albastru (21011121-01)
 
4 Burete magnetic DONAU, 110 x 57 x 25 mm, galben buc. 10.00 5,53 55,30 10,51
 
 
(7638001PL-99)
 
 
5 Calculator de birou Canon WS-1610T, solar, 16 cifre, buc. 1.00 71,11 71,11 13,51
 
 
afisaz inclinat, format mare (WS1610T)
 
6 Capse zincate OFFICE Products 24/6, 1000 buc/cutie buc. 5.00 1,12 5,60 1,06
 
 
(18072419-19)
 
 
7 Creion grafic Eco, ascutit, cu radiera, corp verde buc. 20.00 0,40 8,00 1,52
 
 
(SOIS432)

8 Creion mecanic BIC Matic, 0.7 mm (601021) buc. 4.00 1,88 7,52 1,43

9 Dosar din plastic cu sina si doua perforatii OFFICE buc. 250.00 0,35 87,50 16,63

Products, albastru (21104211-01)

10 Dosar din plastic cu sina si doua perforatii OFFICE buc. 100.00 0,35 35,00 6,65

Products, roz (21104211-13)

pagina 1 / 3

 797638

             
11 Folie protectie OFFICE Products, A4, coaja portocala, 40 buc. 5.00 6,53 32,65 6,20
 
 
microni, 100 file/set (21141215-90)
 
 
12 Folie protectie OFFICE Products, A4, coaja portocala, 40 buc. 20.00 6,51 130,20 24,74
 
 
microni, 100 file/set (21141215-90)
 
13 Marker whiteboard Eco, varf rotund, albastru (SOIS535A) buc. 104.00 1,33 138,32 26,28
 
 
14 Marker whiteboard Eco, varf rotund, negru (SOIS535N) buc. 2.00 1,33 2,66 0,51
 
 
15 Marker whiteboard Eco, varf rotund, rosu (SOIS535R) buc. 2.00 1,33 2,66 0,51
 
16 Notite adezive OFFICE Products,  51 x 76 mm, galben pal,  buc. 5.00 1,65 8,25 1,57
 
 
100 file (14047511-06)
 
 
17 Organizator de birou DONAU Clasic VII, 6 compartimente, buc. 2.00 30,67 61,34 11,65
 
 
155 x 105 x 101 mm, transparent (7476001-99)
 
18 Panou din pluta Bi-Office, 60 x 90 cm, rama lemn buc. 1.00 32,96 32,96 6,26
 
 
(GMC070012010)
 
 
19 Pioneze color Eco, tinte pentru pluta , 40 buc/cutie buc. 1.00 2,16 2,16 0,41
 
 
(SOBO612)
 
20 Pix fara mecanism Eco, varf de 1 mm, albastru (SOIS405A) buc. 110.00 0,33 36,30 6,90
 
 
21 Plic C4 (229 x 324 mm), alb, siliconic, 10/set buc. 2.00 2,15 4,30 0,82
 
 
(15223619-14)
 
 
22 Tus pentru stampila Pelikan, cu picurator, 28 ml, negru buc. 1.00 6,93 6,93 1,32
 
(351197)

Notice that the item description sometimes is after the total price. Problem is that the space between items isn't even, it's variable, like for e.g. position 8 and 9 are almost linked, compared to position 20 and 21 which have a lot of space between them.

Somebody helped me and got only the first line using

\d{1,2}(.*)(\d+\.\d+\s+)(\d+\,\d+\s{0,1}){3}

this is where I got stuck because of the uneven syntax.

It only gets the first line. For e.g.: ''' 16 Notite adezive OFFICE Products, 51 x 76 mm, galben pal, buc. 5.00 1,65 8,25 1,57

100 file (14047511-06) ''' it gest only 16 Notite adezive OFFICE Products, 51 x 76 mm, galben pal, buc. 5.00 1,65 8,25 1,57 but not 100 file (14047511-06). The complete invoice description is Notite adezive OFFICE Products, 51 x 76 mm, galben pal, 100 file (14047511-06) when transformed from pdf to text this is how I get the files.

Will need to extract also the last part and merge the first one to get the full item description.

Thank you

1
it works fine and gets all line, what's your problem with it? - Alireza
it only gets the first one. For e.g.: ''' 16 Notite adezive OFFICE Products, 51 x 76 mm, galben pal, buc. 5.00 1,65 8,25 1,57 100 file (14047511-06) ''' it gest only "16 Notite adezive OFFICE Products, 51 x 76 mm, galben pal, buc. 5.00 1,65 8,25 1,57" but not "100 file (14047511-06)". The complete invoice description is "Notite adezive OFFICE Products, 51 x 76 mm, galben pal, 100 file (14047511-06)" when transformed from pdf to text this is how I get the files. - RKTM

1 Answers

0
votes

Try this regex:

\d{1,2}(.*)(\d+\.\d+\s+)(\d+\,\d+\s?){3}([\n ]+[^(\n]*\([^)]+\)(?=\n))?

Test on regex101