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

Incorrect results for repeat operators #56

Open
kkos opened this issue Feb 12, 2021 · 3 comments
Open

Incorrect results for repeat operators #56

kkos opened this issue Feb 12, 2021 · 3 comments

Comments

@kkos
Copy link

kkos commented Feb 12, 2021

(1) Matching a? or a* with an empty string failed.
(2) Using nested repeat operators failed. For example, a?+ with string "a".

@kokke
Copy link
Owner

kokke commented Feb 13, 2021

Hi @kkos and thanks for the notice 👍

Could you please provide some code so I can be certain what cases we are talking about.

Could you perhaps make a PR editing some of https://github.com/kokke/tiny-regex-c/blob/master/tests/test1.c to showcase exactly the cases you're talking about in 1) 2) ?

That would help me understand your issue :)

@kkos
Copy link
Author

kkos commented Feb 13, 2021

I don't even know if it supports nested repeat operators in the first place, so I'll refrain from writing a PR.
But if you want to match the Python result, you would have something like this:

  { OK,  "a?",                        "",                 (char*) 0      },
  { OK,  "a?",                        "a",                (char*) 0      },
  { OK,  "a*",                        "",                 (char*) 0      },
  { OK,  "a??",                       "a",                (char*) 0      },
  { OK,  "a?*",                       "a",                (char*) 0      },
  { OK,  "a?+",                       "a",                (char*) 0      },
  { OK,  "a*?",                       "a",                (char*) 0      },
  { OK,  "a**",                       "a",                (char*) 1      },
  { OK,  "a*+",                       "a",                (char*) 1      },
  { OK,  "a+?",                       "a",                (char*) 0      },
  { OK,  "a+*",                       "a",                (char*) 1      },
  { OK,  "a++",                       "a",                (char*) 1      },

The Python code I tested:

#!/usr/bin/env python3                                                          
# -*- coding: utf-8 -*-                                                         

import re

# (1)                                                                           
print(re.match(r'a??', ""))
#=>  <re.Match object; span=(0, 0), match=''>                                   

print(re.match(r'a??', "a"))
#=>  <re.Match object; span=(0, 0), match=''>                                   

print(re.match(r'a*', ""))
#=>  <re.Match object; span=(0, 0), match=''>                                   

# (2)                                                                           
print(re.match(r'(?:a??)??', "a"))
#=> <re.Match object; span=(0, 0), match=''>                                    

print(re.match(r'(?:a??)*', "a"))
#=> <re.Match object; span=(0, 0), match=''>                                    

print(re.match(r'(?:a??)+', "a"))
#=> <re.Match object; span=(0, 0), match=''>                                    

print(re.match(r'(?:a*)??', "a"))
#=> <re.Match object; span=(0, 0), match=''>                                    

print(re.match(r'(?:a*)*', "a"))
#=> <re.Match object; span=(0, 1), match='a'>                                   

print(re.match(r'(?:a*)+', "a"))
#=> <re.Match object; span=(0, 1), match='a'>                                   

print(re.match(r'(?:a+)??', "a"))
#=> <re.Match object; span=(0, 0), match=''>                                    

print(re.match(r'(?:a+)*', "a"))
#=> <re.Match object; span=(0, 1), match='a'>                                   

print(re.match(r'(?:a+)+', "a"))
#=> <re.Match object; span=(0, 1), match='a'>                                   

@kokke
Copy link
Owner

kokke commented Feb 13, 2021

Hi @kkos and thanks for helping me understand the issue 👍

I don’t think the nested operators are supported easily, but I will have a look and get back to you

matyalatte added a commit to matyalatte/tiny-str-match that referenced this issue Jul 5, 2024
matyalatte added a commit to matyalatte/tiny-str-match that referenced this issue Jul 5, 2024
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