I'm trying to build a random external ID generator that can take a complex pattern described in RegEx and generate any number of unique strings for unit tests.
Ideally something like Xeger which makes it really simple.
I'm considering a lengthy process of indexing separators, removing them, randomizing a string and restoring separators but that's not as portable across ID formats. Any suggestions for creative solutions?
This would be useful in unit tests for following patterns like Social Security Numbers or Phone Numbers, as well as in code directly for creating new IDs.
Example for Social Security Numbers:
String regex = '[0-9]{3}-[0-9]{2}-[0-9]{4}';
String myId = String.generateRandom(regex);
Pattern myPattern = Pattern.compile(regex);
Matcher myMatcher = MyPattern.matcher(myId);
System.assert(myMatcher.matches());
I also submitted an idea to the IdeaExchange for this, so if you think it's worthy, please vote!