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

Different output result with different word order #21

Open
templarundead opened this issue Dec 31, 2017 · 2 comments
Open

Different output result with different word order #21

templarundead opened this issue Dec 31, 2017 · 2 comments

Comments

@templarundead
Copy link

#Example 1
input: ghost frost pos
output: ghost|frost|pos
expected output: (?:(?:fr|gh)ost|pos)
Example 2
input: pos ghost frost
output: (?:gh|fr)ost|pos
expected output: (?:(?:fr|gh)ost|pos)

@mathiasbynens
Copy link
Contributor

Hmm… So let’s sort the input words by length ([...word].length) and then lexicographically?

@vegeta897
Copy link

vegeta897 commented Feb 15, 2018

That happens to work for ghost frost pos, but with my set of 100+ junk words, sorting from longest to shortest, then by Z-A, happens to generate the shorter RX (though not by much, 594 chars vs. the 608 with ascending length and A-Z). I also tried reversing the characters of each word when sorting A-Z and Z-A but this made no difference.

An interesting optimization problem. It would help if I actually looked at what regexgen was doing under the hood 😛

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

3 participants