02-06-2018 09:18 PM
I work on labview application which needs to scan various bar-codes and match them to regular expressions from database. For testing purpose I would like to solve opposite task - be able to generate some random strings which are matching to my specific regular expressions. Strings are kind of long, up to 16 characters, various length, so dirty brute-force in while-loop until match found does not look like a good idea. Are there any better ideas?
Below is a sample of my regular expressions: [0-9A-F]{8}[0-3C]{1}[0-9A-F]{4}A:[0-9A-F]{1}
Solved! Go to Solution.
02-07-2018 01:04 AM - edited 02-07-2018 01:05 AM
Hi Serge,
[0-9A-F]{8}[0-3C]{1}[0-9A-F]{4}A:[0-9A-F]{1}
So you need an 8-digit hexadecimal formatted number, followed by one char of [0123C], followed by a 4-digit hex number, "A:" and at last a one-digit hex number?
Generate 4 random numbers, scale them as needed (U32, U16) and use FormatIntoString to generate your "barcode". (For [0123C] I would use an IndexArray function with an array constant containing those chars.)
02-07-2018 04:15 AM
wrote:Below is a sample of my regular expressions: [0-9A-F]{8}[0-3C]{1}[0-9A-F]{4}A:[0-9A-F]{1}
There is no random length in this match. To match it needs:
exactly 8X (0-9 or A-F)
exactly 1X (0-3 or C), not 0 to 3C btw.
exactly 4X (0-9 or A-F)
exactly A:
exactly 1X (0-9 or A-F)
This could be simplified to: [0-9A-F]{8}[0-3C][0-9A-F]{4}A:[0-9A-F]
If those numbers are the minimum, you should use: [0-9A-F]{8,}[0-3C]{1,}[0-9A-F]{4,}A:[0-9A-F]{1,}.
There is not one technique that will generate this. You'll need a variety of code:
1) to generate a 0-0xF digit, multiply a random number with 15, convert to integer, convert to string.
2) to generate 8 or more of them, multiply a random number with the max, and add 8. Convert to integer and execute 1) in a for loop.
3) to generate 0 to 3 or C, make a string array with 0,1,2,3,C, and use a random number X 4 (not 5!) to index it.
4) to generate nX3), same as 2.
5) repeat 2 and 4, and concatenate the results.
Note that carefully chosen sub VI's will make your life a lot easier...