RegexMyGenerator

FREEMIUM
By RegexMyAPIs | Updated 15 days ago | Text Analysis
Popularity

5.5 / 10

Latency

1,568ms

Service Level

100%

Health Check

N/A

Followers: 2
Resources:
Product Website Terms of use
API Creator:
Rapid account: Regex My AP Is
RegexMyAPIs
RegexMyAPIs
Log In to Rate API
Rating: 5 - Votes: 1

README

RegexMy Generator: A Natural Language to Regular Expression Generator API

RegexMy Generator is an API that allows you to build regular expressions from natural language descriptions. You can use RegexMy Generator to quickly and easily create complex regex patterns without having to learn the syntax or remember the pattern.

While regexMy Generator may be able to handle basic interactions in other languages to some extent, its proficiency and accuracy are significantly higher in English.

How to use RegexMy Generator

To use RegexMy , you need to send a POST request to the following endpoints:

  • regexmygenerator.p.rapidapi.com/api/generate
  • regexmygenerator.p.rapidapi.com/api/detailedgenerate

The request body should contain a JSON object with the following parameter:

  • pattern: A natural language description of the regex pattern you want to generate. For example, “a valid email address” or “a word that starts with a vowel and ends with a consonant”. The pattern description should be as precise as possible to get the most accurate regex. The maximum length of the pattern is 250 characters.

You can also mention which programming language you are planning to use to get more accurate result for the language you intend to use the regex in example: “a valid email address for python”

If you need any especifics about case sensitive pattern you need to specify that in your description for example “a valid email address for python with only lower case characters” and if you need your pattern to be global match you need to mention this in your description as well for example “a valid email address for python with only lower case characters with global matching”

Accuracy: the more specific you are in descriping your pattern the more accurate regex you get.

The response will be a JSON object with the following fields:

  • status: The status code of the request. A value of 200 means the request was successful and a regex pattern was generated. A value of 400 means the request was invalid and an error message will be provided.
  • response: containing:
    - regex : The generated regex pattern as a string. For example, “\w+@\w+.\w+” or “[aeiou]\w*[bcdfghjklmnpqrstvwxyz]”. This field will only be present if the status is 200.
    -explanation: containing detailed explanation of the generated regex.
  • errorMessage: The error message explaining why the request was invalid. For example, “The pattern is too long” or “The language is not supported”. This field will only be empty string in case of no errors

Examples

Here are some examples of using RegexGen with different patterns, languages, and flags:

Request body:

{“pattern”: “a phone number with 10 digits and optional dashes with global matching for javascript”}

Response sample:

{
    "status": "success",
    "response": {
        "regex": "/(\\d{3}-\\d{3}-\\d{4}|\\d{10})/g"
    },
    "errorMessage": ""
}

Response with explanation sample:

{
    "status": "success",
    "response": {
        "regex": "/(\\d{3}-\\d{3}-\\d{4}|\\d{10})/g",
        "explanation": "This regular expression matches either a phone number in the format xxx-xxx-xxxx or a 10-digit number. The `\\d` represents a digit, and the `{3}` and `{4}` indicate the exact number of occurrences. The `|` symbol acts as an OR operator, allowing the regex to match either the xxx-xxx-xxxx pattern or a 10-digit number. The `/g` at the end of the regex is a global flag, which allows the regex to find all matches within a given input string, rather than just the first match. Overall, this regex can be used to find and validate phone numbers or 10-digit numbers within a text."
    },
    "errorMessage": ""
}

Request body:

{pattern: “a hexadecimal color code with or without the hash sign case insensitive for python”}

Response sample:

{
    "status": "success",
    "response": {
        "regex": "^(?:#)?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$"
    },
    "errorMessage": ""
}

Response with explanation sample:

{
    "status": "success",
    "response": {
        "regex":  "^(?:#)?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$",
        "explanation": "This regular expression is designed to match hexadecimal color codes in the format #RRGGBB or #RGB, where RR, GG, and BB represent the red, green, and blue components of the color in hexadecimal notation.\n\nLet's break down the expression:\n- ^ asserts the start of the string\n- (#)? makes the # symbol optional by using the ? quantifier to match zero or one occurrence of #\n- ([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}) specifies two alternatives separated by |:\n  - [0-9A-Fa-f]{6} matches exactly six characters that can be any digit from 0 to 9 or any letter from A to F in either uppercase or lowercase, representing a complete #RRGGBB color code\n  - [0-9A-Fa-f]{3} matches exactly three characters following the same rules, representing a shorter #RGB color code\n- $ asserts the end of the string\n\nIn summary, the regular expression ensures that the input string represents a valid hexadecimal color code in the form #RRGGBB or #RGB, with the # symbol being optional.\n\nThis regex can be used to validate user input for color selection in web forms or to extract color codes from text data."
    },
    "errorMessage": ""
}

Limitations and Disclaimer

RegexMy is an experimental API that uses natural language processing and machine learning to generate regex patterns. It is not guaranteed to be accurate, complete, or error-free. It may not handle all possible cases or scenarios. It may produce unexpected or invalid results. Use it at your own risk and discretion.

Feedback and Support

If you have any feedback, suggestions, or questions about RegexMy, please contact us at support@regexmy.com. We appreciate your input and we are always looking for ways to improve our service.