Randy Minder
Randy Minder

Reputation: 48522

Regular Expression to generate a string

I am using a tool to generate test data for our database. For columns that are string fields, we have the option of entering a regular expression that will be used to generate values for the column. I would like a regular expression that generates a 15 character string as follows:

  1. Characters 1-6 should consist of the YYMMDD (current year,month,day) such as "100702". If it's not possible for RegEx to determine the current date, a hard-wired value of "100702" would be fine.
  2. Characters 7-8 should be either '25' or '26'
  3. Characters 9-15 should a sequential series of digits starting with '0000001', then '0000002' etc. If this cannot be done, a random, but unique, set of 7 digits would work.

Is this possible?

Upvotes: 1

Views: 1311

Answers (1)

Peter Boughton
Peter Boughton

Reputation: 112210

No, regex does not generate text, it matches text.

However, if you're using Java, take a look at Xeger which can do what you want.


Also, see these similar questions:
Using Regex to generate Strings rather than match them
How do I generate text matching a regular expression from a regular expression?
Reverse regular expressions to generate data

Upvotes: 4

Related Questions