0

am currently trying to generate a string that matches a given regex, I've been working on this for few days without good solution. I tried using the Generex library which works find until i put in some more complicated regex like this

"^((\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)\s*[;]{0,1}\s*)+$"

or

"(?:(NGN|USA|TWN|IND|VN)\h*,?\h*(?!.*\1))+",

this have proven to be the biggest issue I've encountered in Software Engineering Field.

The question is how can i generate random matching String from Regex correctly.

NOTE: Using Regex to generate Strings rather than match them doesn't work for me, Generex works with more simpler format of regex rather than the complicated onces, the two examples above is kinda complicated, but those regex isn't decided by me, so there is no way i can modify it.

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
  • I see a question mark but no question. – shmosel Feb 22 '18 at 02:52
  • Whats the question exactly? – Balwinder Singh Feb 22 '18 at 02:53
  • you mean in the regex ? – Ezell Buoee Feb 22 '18 at 02:54
  • @BalwinderSingh i will edit the question to make it more clearer, the question is how can i generate a string from regex correctly. – Ezell Buoee Feb 22 '18 at 02:56
  • 1
    @shmosel *I see a question mark* I see three – Scary Wombat Feb 22 '18 at 03:00
  • Possible duplicate of [Using Regex to generate Strings rather than match them](https://stackoverflow.com/questions/22115/using-regex-to-generate-strings-rather-than-match-them) – Keerthana Prabhakaran Feb 22 '18 at 03:03
  • @KeerthanaPrabhakaran it isn't really a duplicate, the suggession from that question doesn't work for me, They did advise using Xeger/Generex – Ezell Buoee Feb 22 '18 at 03:20
  • Might be a good fit for CodeGolf like here: https://codegolf.stackexchange.com/q/156315/373 - maybe not welcomed, if you don't have a solution, just ask on meta. I would try the usual way: Didivide and impera. Solve subexpressions, than bigger expressions. Maybe a combination of analisis and brute forcing? – user unknown Feb 22 '18 at 03:45
  • Have you looked at https://stackoverflow.com/questions/22115/using-regex-to-generate-strings-rather-than-match-them? Why Generex/Xeger isn't working for you? – Balwinder Singh Feb 22 '18 at 05:17
  • yes, Generex works with more simpler format of regex rather than the complicated onces, the two examples above is kinda complicated, but those regex isn't decided by me, so there is no way i can modify it – Ezell Buoee Feb 22 '18 at 06:30
  • Xeger works for me with the regular expressions you've provided – GalAbra Feb 22 '18 at 08:54
  • @G i tried using it, but it's generation some characters that isn't recognize and after validating with my PatternMatcher component return false – Ezell Buoee Feb 23 '18 at 02:35

0 Answers0