Regular Expression to generate a string
I am using a tool to generate test data for o开发者_如何学JAVAur 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:
- 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.
- Characters 7-8 should be either '25' or '26'
- 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?
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
精彩评论