Skip to content

Instantly share code, notes, and snippets.

@dai
Last active May 9, 2024 04:26
Show Gist options
  • Save dai/010ad565aef36f192732b33e07d6edfb to your computer and use it in GitHub Desktop.
Save dai/010ad565aef36f192732b33e07d6edfb to your computer and use it in GitHub Desktop.
make a RegEx on the Web in 5 seconds
// Go to https://www.devie.ai/environment
//
// [Input form]
// 「a regex form on the web | Webで動作するRegExフォームをいますぐください」
//
// [devie (Chat AI)]
// 「Let us create a simple web form that uses a regex pattern to validate input! This form can be flexible; for example, validating an email address or any pattern you specify. If you have a specific regex pattern in mind, let me know!」
// Clickhereto view the webpage once the server has started andhereto view the code.
[nix-shell:]# rm -rf ~/daisuke && mkdir ~/daisuke && echo "from flask imporlask, request
> import ssl
>
> app = Flask(__name__)
>
> @app.route('/')
> def index():
> return '''<!DOCTYPE html>
> <html lang=\"en\">
> <head>
> <meta charset=\"UTF-8\">
> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
> <title>Regex Validator</title>
> <style>
> body { font-family: Arial, sans-serif; margin: 20px; }
> .container { display: flex; flex-direction: column; align-items: cer; }
> input[type=text] { margin: 10px 0; padding: 10px; }
> .submit-btn { padding: 10px 20px; background-color: #007BFF; color:ite; border: none; border-radius: 5px; cursor: pointer; }
> .submit-btn:hover { background-color: #0056b3; }
> </style>
> </head>
> <body>
> <div class=\"container\">
> <h2>Input Validator</h2>
> <form action=\"/validate\" method=\"post\">
> <input type=\"text\" name=\"userInput\" pattern=\"[A-Za-z0-9]{5" title=\"Minimum 5 letters or numbers.\" required>
> <input type=\"submit\" value=\"Validate\" class=\"submit-btn\">
> </form>
> </div>
> </body>
> </html>'''
>
> @app.route('/validate', methods=['POST'])
> def validate():
> user_input = request.form['userInput']
> # Here you can add more validation logic with Python
> return '<h3>Input validated successfully: {}</h3>'.format(user_input)
>
> if __name__ == '__main__':
> app.run(host='0.0.0.0', port=7000, ssl_context=('/app/src/cert.pem', '//src/key.pem'))
> " > ~/daisuke/main.py && cd ~/daisuke && cp /app/src/key.pem . && cp /app/scert.pem . && cp /app/src/run.sh . && chmod -R a+x .
[nix-shell:~/daisuke]# ./run.sh
./run.sh: line 5: lsof: command not found
Launching app on port 7000...
* Serving Flask app 'main'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on https://127.0.0.1:7000
* Running on https://172.31.70.195:7000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment