Skip to content

Create "regex within regex" for subcategories  #51

@bee-san

Description

@bee-san

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions