Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xeger not handling certain non-capturing groups #36

Open
Pierlou opened this issue Apr 12, 2024 · 2 comments
Open

xeger not handling certain non-capturing groups #36

Pierlou opened this issue Apr 12, 2024 · 2 comments

Comments

@Pierlou
Copy link

Pierlou commented Apr 12, 2024

Hi, thanks for this lib!
I have come across a weird behaviour using rstr.xeger: this pattern "(?:(?:^|;)(AAA|BBB|CCC))+$" aims to capture any string that contains groups of strings within ["AAA", "BBB", "CCC"], separated by semicolons. These are valid strings:

  • BBB;AAA
  • BBB;AAA;BBB
  • CCC

However xeger returns things like:

  • BBBCCC;CCCBBB : some groups are not separated
  • ;AAA;BBBCCC : the separator is also at the start of the string
@bjmc
Copy link
Collaborator

bjmc commented Apr 12, 2024

Interesting. Someone else opened an issue asking about non-capturing groups, so I wonder if there's something we're handling incorrectly in that situation. I'll try to investigate when I have some time, but I'm also happy to review a PR if you're feeling ambitious. The group-handling is here.

@bjmc
Copy link
Collaborator

bjmc commented Apr 13, 2024

I think the issue here is how we're handling the ^ character in combination with the + repeat.

A slightly modified version of your regex, '(?:(?:;)(AAA|BBB|CCC))+$' produces correctly matching strings. For example:

  • ;AAA;BBB;BBB;CCC;BBB
  • ;BBB;CCC;BBB;BBB;CCC;BBB;AAA;CCC;AAA;BBB;BBB

the separator is also at the start of the string

I think that's correct? In the group (?:^|;) this regex is saying match either the start-of-input anchor ^ or a semicolon ;. Unless there's something I'm misunderstanding, it's legitimate to start with ;

some groups are not separated

I think this is the bug, more or less: the "not separated" cases are the result of the situation where random.choice() has picked the ^ instead of the ; but we don't output any printable character for "start of input" so we wind up with repeats that are missing separators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants