I am trying to extract the data out of an encoded 2D barcode. The extraction part is working fine, and I can get the value in a text input.
E.g., the decoded string is
]d20105000456013482172012001000001/:210000000001
Based on the following rules (couldn't get the proper table markdown thus attaching a picture), I am trying to extract the substrings from the string mentioned above.
Substrings I want to extract:
05000456013482 (which is after the delimiter 01)
201200 (which is after delimiter 17)
00001 (which is after delimiter 10)
0000000001 (which is after delimiter 21)
P.S - > the first 3 chars in the original string (]d2) are always the same since it just simply signifies the decoding method.
Now some quirks:
1) The number of letters after delimiter 10 is not fixed. So, in the above-given example even though it is 00001 it could be even 001. Similarly, the number of letters after delimiter 21 is also not fixed and it could be of varying length.
For different length delimiters, I have added a constant /: to determine when encoding has ended after scanning through a handheld device.
Now, I have a look for /: after delimiter 10 and extract the string until it hits /: or EOL and find delimiter 21 and remove the string until it hits /: or EOL
2) The number of letters after delimiter 01 and 17 are always fixed (14 letter and six letters respectively)
as shown in the table.
Note: The position of delimiters could change. In order words, the encoded barcode could be written in a different sequence.
]d20105000456013482172012001000001/:210000000001 - Note: No /: sign after 21 group since it is EOL
]d2172012001000001/:210000000001/:0105000456013482 - Note: Both 10 and 21 group have /. sign to signify we have to extract until that sign
]d21000001/:210000000001/:010500045601348217201200 - First two are of varying length, and the next two are of fixed length.
I am not an expert in regex and thus far I only tried using some simple patterns like (01)(\d*)(21)(\d*)(10)(\d*)(17)(\d*)$ which doesn't work in the given an example since it looks for 10 like the first 2 chars. Also, using substring(x, x) method only works in case of a fixed length string when I am aware of which indexes I have to pluck the string.
P.S - Either JS and jQuery help is appreciated.
