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

Add support for list of regex in regex.json #227

Open
ghost opened this issue Nov 3, 2021 · 4 comments · May be fixed by #244
Open

Add support for list of regex in regex.json #227

ghost opened this issue Nov 3, 2021 · 4 comments · May be fixed by #244

Comments

@ghost
Copy link

ghost commented Nov 3, 2021

Is your feature request related to a problem? Please describe.
Many regexes (like phone numbers or coordinates) have several formats. Currently, | can be used to separate formats, but it makes regex longer and harder to understand.

Describe the solution you'd like
"Regex" should be a list of regexes.

@ghost ghost changed the title Add support for list of regex in regex.Jain Add support for list of regex in regex.json Nov 3, 2021
@GauriBodke
Copy link

Hi, I would like to know about this issue in detail. Do you want multiple regex patterns separated by vertical pipe ( | ), or do you want any change in the code to support a list of regex patterns?

I can solve this issue by creating following blocks with different regex pattern for different type of phone Number Patterns.

      "Name": "Phone Number",
      "Regex": "^(\\s*(?:\\+?(\\d{1,3}))?[-. (]*(\\d{3})[-. )]*(\\d{3})[-. ]*(\\d{4})(?: *x(\\d+))?\\s*)$",
      "plural_name": false,
      "Description": null,
      "Rarity": 0.5,
      "URL": null,
      "Tags": [
         "Identifiers",
         "Credentials",
         "Phone Number",
         "Phone"
      ],
      "Children": {
         "path": "phone_codes.json",
         "entry": "Location(s): ",
         "method": "hashmap"
      },
      "Examples": {
         "Valid": [
            "202-555-0178",
            "+1-202-555-0156",
            "+662025550156",
            "+356 202 555 0156"
         ],
         "Invalid": []
      }
   }```

@ghost
Copy link
Author

ghost commented Dec 3, 2021

I would like to have a list of regexp, so yes, changes in code are needed. Pywhat should concatenate all these regexes into one using pipes(|). Therefore, only regex loader function should be updated.

@GauriBodke
Copy link

Hey, I am able to combine regex patterns dynamically using |. What is your suggestion for combining other parameters of the block, such as Description, Rarity, URL, Tags, Children, and Examples.

@amadejpapez
Copy link
Collaborator

amadejpapez commented Dec 11, 2021

Hi! I will take our THM flag regex to better show what we want to achieve. (The only part changed is Regex)

We want to separate multiple regex formats of one identifier into a list of regexes, instead of having all of them together and separated by |. Some of regexes are quite long and seeing where is what is getting harder, so our goal is to improve their readability.

I am not sure how PyWhat should use them after tho. Merged them back into one with | or search with each regex separately. Probably the latter.

I hope this clears some things. Maybe @bee-san has some more suggestions. :)

   {
      "Name": "TryHackMe Flag Format",
      "Regex": ["(?i)^thm{.*}$", "(?i)^tryhackme{.*}$"],
      "plural_name": false,
      "Description": "Used for Capture The Flags at https://tryhackme.com",
      "Rarity": 1,
      "URL": null,
      "Tags": [
         "CTF Flag"
      ],
      "Examples": {
         "Valid": [
            "thm{hello}"
         ],
         "Invalid": []
      }
   }

@GauriBodke GauriBodke linked a pull request Dec 11, 2021 that will close this issue
1 task
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.

2 participants