-1

I want to create an own unique key which is 6 characters long and includes the following regex characters and numbers: [a-z][0-9] e.g.: 00000A, 00000B, ... 00000Z, 00001A, 00001B,...

I don't know how to create this algorithm of these regex formation.

Has someone an idea, how to create this algorithm?

1 Answers1

2

First, your regexp does not match the numbers you're showing as examples. So you'd need to make up your mind there :)

Second, you can simply use a base-36 number probably, and somehow keep track of the last number generated (e.g. using a properties file or database field) in a synchronized singleton.

Then create a simple method that turns the number into a String and left pad that number with zeros until you reach the desired length.

jwenting
  • 5,505
  • 2
  • 25
  • 30