Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:10:32+00:00 2026-05-23T00:10:32+00:00

below is my pattern which is working fine against the given string. local tempRec

  • 0

below is my pattern which is working fine against the given string.

local tempRec = [[

ABC01-USD-0322-A Total DUE amount : 2312.08  USD
Value Date : 31 MAY       2011
   Details:ABCDE - BCD: / ABC01 0212 23.79 / ARM01 0311 870.79
   Details:FGHIJ - BCD: / ABC01 0323 1.88
   Details:KLMNO - BCD: / ABC01 0314 1,035.99
   Details:PQRST - BCD: / ABC01 0315 677.61
   Details:UVWXY - BCD: / ABC01 0316 362.75
   Details:ZABCD - BCD: / ABC01 0317   0.28

   ]]

paytternToMatch = "(%w%w%w[%w%d][%w%d]%-.-%d%p%d%d\n)\n[\n]*"

 for w in string.gmatch(tempRec, paytternToMatch) do
       print(w)
 end

But when I am removing 0 from the last row in the below mentioed string. The pattern is not matching. any help would be appreicated.

local tempRec = [[

ABC01-USD-0322-A Total DUE amount : 2312.08  USD
Value Date : 31 MAY       2011
   Details:ABCDE - BCD: / ABC01 0212 23.79 / ARM01 0311 870.79
   Details:FGHIJ - BCD: / ABC01 0323 1.88
   Details:KLMNO - BCD: / ABC01 0314 1,035.99
   Details:PQRST - BCD: / ABC01 0315 677.61
   Details:UVWXY - BCD: / ABC01 0316 362.75
   Details:ZABCD - BCD: / ABC01 0317   .28

   ]]
paytternToMatch = "(%w%w%w[%w%d][%w%d]%-.-%d%p%d%d\n)\n[\n]*"

 for w in string.gmatch(tempRec, paytternToMatch) do
       print(w)
 end

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:10:33+00:00Added an answer on May 23, 2026 at 12:10 am

    The short answer is that the digit before the punctuation is not optional in your pattern. Simply add a * to match as many digits, but allowing no digits as well. The other option is to use a ? if you only want to match a single or no digits, but not any additional digits before that.

    paytternToMatch = "(%w%w%w[%w%d][%w%d]%-.-%d*%p%d%d\n)\n[\n]*"
    --                                          ^ here
    

    Note that there are several other improvements that you may want to consider in addition to this. For example, this will ignore that digit entirely since the previous .- will include it, change the punctuation to only allow a ., and change the line feed requirement a bit:

    paytternToMatch = "(%w%w%w[%w%d][%w%d]%-.-%.%d%d\n)\n+"
    

    See Programming in Lua for more detail on patterns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Java project in which I have the getter method below
I'm maintaining a web application that utilizes the provider pattern as described below, for
Below is my current char* to hex string function. I wrote it as an
Below is part of the XML which I am processing with PHP's XSLTProcessor :
EDIT: See my working code in the answers below. In brief: I have a
I am new to the MVVM design pattern, and I am working on a
I've been working with web-forms and I want to switch to the MVC pattern
I'm looking for some thoughts on which design pattern(s) to use for my problem,
Consider the automation-compatible COM library in C#, given below. It follows a common COM
I am working on a project where I am implementing a SaveSettings method which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.