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

matchlen may be wrong #53

Open
xavieryin opened this issue Feb 9, 2021 · 5 comments
Open

matchlen may be wrong #53

xavieryin opened this issue Feb 9, 2021 · 5 comments

Comments

@xavieryin
Copy link

int match_len;
char* s = "aa";
char* p = ".*a.*a";
int match_idx = re_match(p, s, &match_len);

expected: match_len == 2
result: match_len == 3

@xavieryin
Copy link
Author

Is anyone also facing this problem?
Or am I doing something incorrectly?

@kkos
Copy link

kkos commented Mar 1, 2021

Yes, I did. I had the same result as you.
And in the next pattern and string, returns length=5.

pattern = ".*a.+a"
string = "aaa"

@xavieryin
Copy link
Author

Quick note: tried #63 , but no luck

@xavieryin
Copy link
Author

no luck by applying #61

@essele
Copy link

essele commented Dec 11, 2023

Hi,

I'm not sure if this is the same issue, but I'm matching "\n\n+" in a simple text file (looking for multiple-newline separated paragraphs, and I noticed that matchlen was actually counting every \n that it came across rather than just the number of them actually matching the pattern.

The fix is simple ... in re_matchp() matchlen is not zero'd when you get a matchpattern() failure. I simply added a "*matchlength = 0" as the last line in the do/while loop and it seems to be working perfectly ... I will do some more testing.

Regards,

Lee.

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