SonOfLilit / kleenexp

modern regular expression syntax everywhere with a painless upgrade path
MIT License
73 stars 16 forks source link

Nongreedy quantifier treated as greedy #33

Open JoshuaFox opened 1 year ago

JoshuaFox commented 1 year ago

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}"