Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a support for multiple regex for lines plugin? #238

Closed
AshNTU opened this issue Jun 22, 2019 · 3 comments
Closed

Is there a support for multiple regex for lines plugin? #238

AshNTU opened this issue Jun 22, 2019 · 3 comments

Comments

@AshNTU
Copy link

AshNTU commented Jun 22, 2019

I have been using the library for some time to parse my company invoices. I encountered that for my invoices I have line items which can be either of the two format. One way is that I create two templates file for each of it or if there is support for the multiple regex for lines and parser just picks the one for which match has been found.

@AshNTU AshNTU changed the title is there a support for multiple regex for lines plugin? Is there a support for multiple regex for lines plugin? Jun 22, 2019
@m3nu
Copy link
Collaborator

m3nu commented Jun 25, 2019

For many fields, you can add a list of regex in the template and it will try all of them. I'm not sure if the line plugin is implemented in a similar way. If not, just add it and open a pull request.

@rmilecki
Copy link
Collaborator

Right now lines parser supports only one set of rules like:

fields:
  lines:
    parser: lines
    start: Item\s+Discount\s+Price$
    end: \s+Total
    line: (?P<description>.+)\s+(?P<discount>\d+.\d+)\s+(?P<price>\d+\d+)

Whenever I deal with company that randomly adds and removes some column I make it optional with a ?, e.g.

line: (?P<description>.+)\s+(?P<discount>\d+.\d+)?\s+(?P<price>\d+\d+)

(in above example discount is optional)


As I understand it you're dealing with company that uses one or more completely different layouts for its lines-covered section?

So are you looking for support for something liike

fields:
  lines:
    parser: lines
    rules:
      - start: Item\s+Discount\s+Price$
        end: \s+Total
        line: (?P<description>.+)\s+(?P<discount>\d+.\d+)\s+(?P<price>\d+\d+)
      - start: Item\s+Price$
        end: \s+Total
        line: (?P<description>.+)\s+(?P<price>\d+\d+)

Is that correct?

@bosd
Copy link
Collaborator

bosd commented Mar 18, 2023

Implemented in #463

@bosd bosd closed this as completed Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants