curious-odd-man / RgxGen

Regex: generate matching and non matching strings based on regex pattern.
Apache License 2.0
86 stars 14 forks source link

generate returns String which does not match the Regex #107

Open hofi1 opened 5 months ago

hofi1 commented 5 months ago

Describe the bug The generate function returns strings, which do not match the given RegEx

To Reproduce

  1. With regex pattern '(?=(abc.*))(?=([a-z0-5]*))'
  2. Use code/API
    
    RgxGen rgxGen = RgxGen.parse(regex);
    Random rnd = new Random(1234);

for (int counter = 0; counter < 100000; counter++) { String generatedString = rgxGen.generate(rnd); System.out.println(generatedString); assertTrue(matchesParser.parse(generatedString), "String: \'" + generatedString + "\' SHOULD match the regex: " + regex); }



4. See error
Generates String "abc(dfCxVLcJ P1&y~pw|Te`6b<Z^&jNUyG!H8nin<bug_\\wV4]Z1*b+H3<Fk`mcrbgx225ur2uekvxenraybvjpmdv3ot15fh53l4kmmq53iyens5rzkatqon"

**Expected behavior**
Generate a string which matches the regex

**Screenshots**
<img width="1086" alt="Screenshot" src="https://github.com/curious-odd-man/RgxGen/assets/61789910/76f5205f-eae2-41e6-9502-3f8e1b12a338">

**Environment:**
 - OS: OSX 14.4.1 (23E224)
 - JDK/JRE version Amazon Corretto 21.0.2
 - RgxGen Version Maven Central 2.0
curious-odd-man commented 5 months ago

Hello! Thanks for reporting this.

Please note that this is a known issue - lookaround patterns do not function properly due to design limitations. This is also mentioned in Readme - section Limitations.

Best Regards, Vlad