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

can not match such string “869759002514931” #21

Open
violet701 opened this issue Oct 25, 2018 · 10 comments
Open

can not match such string “869759002514931” #21

violet701 opened this issue Oct 25, 2018 · 10 comments

Comments

@violet701
Copy link

the string is just 15 fixed digits witch is start by "86". i have check the pattern "\d{15}", "[0-9]{15}" ,"^[0-9]{15}$" and they all cannot match correctly. what is wrong with it?

@kokke
Copy link
Owner

kokke commented Oct 25, 2018

Hi @violet701

The quantifier-operator ({number-of-matches}, {min-matches, max-matches) is not supported. I think that's the problem you're experiencing.

As a small hack, maybe you can replace \d{15} with \d+ or \d\d\d\d\d\d\d\d\d\d\d\d\d\d\d...?

@monolifed
Copy link
Contributor

Adding the matching function doesn't seem hard

static int matchquantifier(regex_t p, regex_t* pattern, const char* text, int min, int max)
{
  max -= min;
  while (min > 0 && *text && matchone(p, *text++))
  {
    min--;
  }
  if (min > 0)
    return 0;
  do
  {
    if (matchpattern(pattern, text))
      return 1;
    max--;
  }
  while (max > 0 && *text && matchone(p, *text++));

  return 0;
}

But you'd probably need another array to store mins and maxs

@kokke
Copy link
Owner

kokke commented Oct 25, 2018

Hi @monolifed

Maybe you could extract the min/max limits from the pattern before calling the matching function, avoiding the need to add extra variables holding the min/max values?

@monolifed
Copy link
Contributor

Right.
https://github.com/monolifed/tiny-regex-c/tree/quantifier

@kokke
Copy link
Owner

kokke commented Oct 26, 2018

Wow that looks really promising @monolifed :) i will review the code later today / this evening.

I expect i will merge your PR #22 as well :)

@kokke
Copy link
Owner

kokke commented Oct 26, 2018

@monolifed

I have run a few tests on your quantifier-branch, and I really like it so far.

If you make another PR adding the quantifier functionality (or add it to #22), I will merge it.

@violet701
Copy link
Author

oh, it's GREAT!!!

@kokke
Copy link
Owner

kokke commented Feb 15, 2021

Hey @monolifed - will you make a PR with the quantifier-addition? I think I somehow dropped this on the floor.

I am not sure how to review which additions were made besides the addition of the matchquantifier-function. Maybe you have a better recollection/overview?

@monolifed
Copy link
Contributor

I don't really remember well

@kokke
Copy link
Owner

kokke commented Feb 15, 2021

😆

I'll try and see if I can get time to clone the branch, pull from master and diff against it. That should do it no? I don't think that branch is any unmergeable changes behind.

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