简体   繁体   English

正则表达式从带有空格分隔符和描述中的空格的行中读取发票行详细信息

[英]Regex to read Invoice Line Details from line with space delimiter and spaces in description

To any REGEX Gurus... I am trying to get the specific RegEx to read the values in an invoice line and return them into named groups as follows.对于任何 REGEX 大师...我正在尝试让特定的 RegEx 读取发票行中的值并将它们返回到命名组中,如下所示。

the invoice lines look like发票行看起来像

ABC08-388 THIS IS DECSCRIPTION WITH SPACES AND APOSTROPIES 80’s ctn 1 1 0 99.90 99.90 9.99 109.89
1233 ANOTHERLINE W/O APOSTROPHEIES each 100 100 0 1.05 105.00 10.50 115.50
XYZ-1234 ANOTEHR LINE WITH APOSTROPHE’S AND SLASH/S box 1 1 0 8.60 8.60 0.00 8.60

the Separation is分离是

Part Number - From Start of line until the first space 
Description - Everything between Part Number and Box Description
Box Description - From end of Description to next group (Space separator)
Qty Ordered - Integer (Space separator)
Qty Delivered - Integer (Space separator)
Qty Back Order - Integer (Space separator)
Box Cost - Decimal number  (Space separator)
Line Total Ex Tax - Decimal number  (Space separator)
Line Tax -Decimal number  (Space separator)
Line Total Incl Tax EOL

I am looking for something along the lines of - But I just cant get all the Thing working... Please any help will be greatly appreciated我正在寻找类似的东西 - 但我无法让所有的东西正常工作......请任何帮助将不胜感激

^(?<SupplierPartNumber>([A-Za-z0-9-_]+)) (?<SupplierDescription>([.])).(?<BoxQty>([0-9]+([\,\.][0-9]+)){1}(?<DeliveredQty>([0-9]+([\,\.][0-9]+)){1}(?<OnBackOrder>([0-9]+([\,\.][0-9]+)){1} (?<BoxCost>([0-9]+([\,\.][0-9]+)){1}(?<LineTotalEx>([0-9]+([\,\.][0-9]+)){1}(?<GSTAmount>([0-9]+([\,\.][0-9]+)){1} (?<LineTotalInc>([0-9]+([\,\.][0-9]+)){1}

Take a look at this, hopefully it will be helpful.看看这个,希望对你有帮助。 You might need to edit the individual group contents to use the correct format for each part, but you get the point hopefully.您可能需要编辑各个组的内容以对每个部分使用正确的格式,但希望您能明白这一点。

(?<SupplierPartNumber>^[A-Za-z\d-_]+)\s(?<Description>[a-zA-Z\s\d’\/]+[a-zA-Z])\s(?<BoxQty>\d+)\s(?<DeliveredQty>\d+)\s(?<OnBackOrder>\d+)\s(?<BoxCost>\d+\.\d+)\s(?<LineTotalExTax>\d+\.\d+)\s(?<LineTaxDecimal>\d+.\d+)\s(?<LineTotal>\d+.\d+$)

Breaking above regex down by each requirement so easier to see:按每个要求打破正则表达式,以便更容易看到:

(?<SupplierPartNumber>^[A-Za-z\d-_]+)\s
(?<Description>[a-zA-Z\s\d’\/]+[a-zA-Z])\s
(?<BoxQty>\d+)\s
(?<DeliveredQty>\d+)\s
(?<OnBackOrder>\d+)\s
(?<BoxCost>\d+\.\d+)\s
(?<LineTotalExTax>\d+\.\d+)\s
(?<LineTaxDecimal>\d+.\d+)\s
(?<LineTotal>\d+.\d+$)

Regex Demo to see in action.正则表达式演示以查看实际操作。

You'll notice I've combined the two Descriptions into one in the above solution.您会注意到我在上述解决方案中将两个描述合二为一。 It is because it wasn't quite clear to me where the Description finished and Box Description started.这是因为我不太清楚描述在哪里完成和盒子描述从哪里开始。 Assuming from your examples that Description contains only caps, then the regex could look like:从您的示例中假设 Description 仅包含大写字母,则正则表达式可能如下所示:

(?<SupplierPartNumber>^[A-Za-z\d-]+)\s(?<Description>[A-Z\s\d’\/]+[A-Z])\s(?<BoxDescription>[a-zA-Z\s\d’\/]+[a-zA-Z])\s(?<BoxQty>\d+)\s(?<DeliveredQty>\d+)\s(?<OnBackOrder>\d+)\s(?<BoxCost>\d+\.\d+)\s(?<LineTotalExTax>\d+\.\d+)\s(?<LineTaxDecimal>\d+.\d+)\s(?<LineTotal>\d+.\d+$)

(?<SupplierPartNumber>^[A-Za-z\d-]+)\s
(?<Description>[A-Z\s\d’\/]+[A-Z])\s
(?<BoxDescription>[a-zA-Z\s\d’\/]+[a-zA-Z])\s
(?<BoxQty>\d+)\s(?<DeliveredQty>\d+)\s
(?<OnBackOrder>\d+)\s
(?<BoxCost>\d+\.\d+)\s
(?<LineTotalExTax>\d+\.\d+)\s
(?<LineTaxDecimal>\d+.\d+)\s
(?<LineTotal>\d+.\d+$)

Regex Demo for the above case.上述案例的正则表达式演示

You'll know better what the separation is between Description and Box Description, so edit the corresponding groups as required.您将更好地了解描述和框描述之间的分隔,因此请根据需要编辑相应的组。 Let me know if you need any more help with this.如果您需要更多帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM