GeeCON Prague 2014*
The moose likes Java in General and the fly likes Generate a string that matches a regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Generate a string that matches a regular expression" Watch "Generate a string that matches a regular expression" New topic
Author

Generate a string that matches a regular expression

Dirk Deneer
Greenhorn

Joined: Jan 04, 2006
Posts: 3
What I want to do sounds so simple, but it looks it is not available in Java. Normally regular expressions are used to check an input string against the expression. But I need it the other way around.
I want to generate a string value which is valid for a regular expression. So for instance if the regular expression is [A-Z][0-9] a good string value will be A0.
I have no control about the regular expressions I will get as input. In fact they can be present in xsd schemas to restrict the valid values in XML messages.
It is OK to have always the same generated string for a specific regular expression, in other words the value does not need to be random. This means [A-Z][09] may always return A0. The only purpose is to get a value that is valid for the regex.

So the signature of this method I need, should be something like this:



I know it is possible to write such a method by myself. But I think it is a lot of work. Anyone who knows of a public library where this method is present?


DickD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generate a string that matches a regular expression