1

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?

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
Randy Minder
  • 47,200
  • 49
  • 204
  • 358
  • you might want to mention what "flavor" of regex you're looking for, as they can vary (for instance, C# versus Javascript) – alex Jul 02 '10 at 12:57
  • I don't think it is possible to get the current date, a incrementing number or a random set of digits out of a regular expression. – Philipp Grathwohl Jul 02 '10 at 13:01
  • Nothing here can be done with a regex, besides the `2[56]` part. However, you can trivially write a function that does that. For the last part, you can use a running ID (for example, on Oracle there's a Sequence) – Kobi Jul 02 '10 at 13:04

1 Answers1

4

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

Community
  • 1
  • 1
Peter Boughton
  • 110,170
  • 32
  • 120
  • 176