Appending a "?" to + and * makes them "non-greedy", meaning they do respect right hand side expressions before capturing all matching characters toward the right.
Thanks.
I think I simplified the problem a bit. I only need to concatenate 4 fields: product number (P), quantity (Q), operator number (O), and lot number (L). All of them are numeric, except for lot number which can contain random alphabets in addition to numbers.
I plan to concatenate such that lot number comes last. So if:
Product number = 100
Quantity = 2000
Operator number = 999
Lot number = 55L888
I will concatenate it as: P100Q2000O999L55L888
I can parse the product number using ^P[0?9]{0,19}, which would give me 100. The subsequent "Q" will be not parsed because it's not a number. Similarly, I can use ^Q[0?9]{0,19} to parse quantity, and ^O[0?9]{0,19} for operator number. This is the beauty when you only deals with purely numeric data.
Lot number is tricky because it can contain alphabets. I want to use ^L[A-Z0?9]{0,19}, but the lot number might have the letter "L" in it, as shown above. This is where "greedy vs non-greedy" comes into play. Based on your answer above, ^L[A-Z0?9]{0,19} should be greedy, so it would capture "55L888" rather than just "55", right?
Please correct me if anything I've mentioned above is wrong. If I understood it correctly, then I believe I got a solution.
Also, the data will be scanned into fields on a form. For the numeric data, will the scanner send it as characters (char) or pure numbers (int) usually?
Thanks