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

Nongreedy quantifier treated as greedy #33

Open
JoshuaFox opened this issue Jan 4, 2023 · 0 comments
Open

Nongreedy quantifier treated as greedy #33

JoshuaFox opened this issue Jan 4, 2023 · 0 comments

Comments

@JoshuaFox
Copy link
Contributor

JoshuaFox commented Jan 4, 2023

See the test below, which shows that the syntax 1+:fewest gives the same results as 1+. Am I using the syntax wrong? Note also this issue, which seems related but not the same.

import re
import ke

 
search_str = "xxxbbcccbeeeeeeeeebxxx"

greedy_kleenexp = ke.search('["b" [1+  #any ] "b"]', search_str, ).group(0)
greedy_regexp = re.search(r'b.+b', search_str, ).group(0)

nongreedy_kleenexp = ke.search('["b" [1+:fewest #any] "b"]', "%s" % search_str, ).group(0)
nongreedy_regexp = re.search(r'b.+?b', search_str, ).group(0)

assert greedy_regexp == greedy_kleenexp, f"{greedy_regexp}!={greedy_kleenexp}"
assert nongreedy_regexp != greedy_regexp, f"{nongreedy_regexp}=={greedy_regexp}"

# fails
assert nongreedy_regexp == nongreedy_kleenexp, f"{nongreedy_regexp}!={nongreedy_kleenexp}"
# fails
assert nongreedy_kleenexp != greedy_kleenexp, f"{nongreedy_kleenexp}=={greedy_kleenexp}"

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

1 participant