• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generate a string that matches a regular expression

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic