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

Create "regex within regex" for subcategories #51

Closed
bee-san opened this issue May 28, 2021 · 4 comments · Fixed by #127
Closed

Create "regex within regex" for subcategories #51

bee-san opened this issue May 28, 2021 · 4 comments · Fixed by #127

Comments

@bee-san
Copy link
Owner

bee-san commented May 28, 2021

Some regex have sub-categories, for example:

  • Mastercard numbers -- the first 4 digits represent what company that card belongs to.
  • Phone numbers. If they start with +44 or 07, it's the UK!

As such, I propose we change our code into:

    {
       "Name": "MasterCard Number",
       "Regex": "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$",
       "plural_name": false,
       "Description": null,
       "Rarity": 0.5,
       "Tags": [
          "Credit Card",
          "Finance"
       ],
        "Children": [
            {
                "Name": "BarclayCard",
                "Regex:" "5117.*"
                Same value as the parent above
            }
        ]
    },

We want to keep the same object for each child in case we have anything special to add like a website or a cool description etc. It doesn't cost us much to do this, but it is helpful!

Also, our regex for the children can be much broader. Read it as:

  1. When I pass the mastercard regex
  2. When I pass the barclaycard regex (which just checks to see if the first few numbers are equal to 5117)
  3. Return
    Because the children only run when the parents do, the child regex can be lighter.

As an aside, Mastercard have very helpfully provided a CSV table of all the companies and what their Mastercard subrange is:
https://www.mastercard.us/en-us/business/issuers/get-support/simplified-bin-account-range-table.html

@bee-san bee-san pinned this issue May 28, 2021
@ghost ghost mentioned this issue May 28, 2021
@bee-san bee-san changed the title Create "regex within regex" Create "regex within regex" for subcategories May 28, 2021
@ghost
Copy link

ghost commented May 28, 2021

By the way, in some situations, the number of children may be too large (like international phone number codes), so I suggest the following for such circumstances:

{
   "Name": "MasterCard Number",
   "Regex": "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$",
   "plural_name": false,
   "Description": null,
   "Rarity": 0.5,
   "Tags": [
      "Credit Card",
      "Finance"
   ],
    "children_path": "mastercard_companies.json"
}

@bee-san
Copy link
Owner Author

bee-san commented May 28, 2021

By the way, in some situations, the number of children may be too large (like international phone number codes), so I suggest the following for such circumstances:

{
   "Name": "MasterCard Number",
   "Regex": "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$",
   "plural_name": false,
   "Description": null,
   "Rarity": 0.5,
   "Tags": [
      "Credit Card",
      "Finance"
   ],
    "children_path": "mastercard_companies.json"
}

When you say 'too large' how large is that?

@ghost
Copy link

ghost commented May 28, 2021

It depends. In my opinion, over 100 lines would be a lot but still bearable. 200+ is too large.

@ghost
Copy link

ghost commented Jul 13, 2021

#114 is a great example where it may be useful.

@ghost ghost self-assigned this Jul 16, 2021
@ghost ghost mentioned this issue Aug 2, 2021
@ghost ghost closed this as completed in #127 Aug 24, 2021
@ghost ghost unpinned this issue Aug 25, 2021
This issue was closed.
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

Successfully merging a pull request may close this issue.

1 participant