firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.28k stars 199 forks source link

Curl against regex101.com and get back an explainer #1711

Open beyarkay opened 2 years ago

beyarkay commented 2 years ago

Feature

Hi! I love the website, use it multiple times a week to check my regex. Often my workflow is that I'll write regex, paste it into the website, and check some test cases or check the explainer to see that I haven't left anything unescaped or similar.

It would be amazing if I could curl against the website and get back a formatted explainer of the regex, similar to how cheat.sh will explain bash commands via curl http://cheat.sh/pwd. Something like:

$ curl regex101.com/explain/[a-z]+
[a-z]+
    ^- one or more times
^^^^- any letter from a to z

This means that from the commandline I can directly paste explainers of complicated regex as comments into my code which would be super useful.

There would be some trickery to escaping regex characters in the URL, but I'm happy to help out if this feature is put on the roadmap.

For reference

This is how cheat.sh works:

$ curl cheat.sh/pwd
 cheat:pwd
# Show the absolute path of your current working directory:
pwd

 tldr:pwd
# pwd
# Print name of current/working directory.

# Print the current directory:
pwd

# Print the current directory, and resolve all symlinks (i.e. show the "physical" path):
pwd -P

It also colour codes the various parts, but that's more of a nice-to-have

firasdib commented 2 years ago

The major blocker for this is CPU. This is quite an expensive operation, and the server would likely not be able to handle this additional load. On top of that, the current output from the explanation isn't very "api/cli friendly", which means it'd have to be reworked quite a bit.

asirota commented 2 years ago

I wonder of a regex101 REST API would be a more generic approach. This could start with a simple way to test expressions against input. The explainer text could be more easily structured into a json response possibly. Just an idea. One that may be commercially viable as you may wish to charge or only allow the API to be used under certain conditions.