Giter Site home page Giter Site logo

geongeorge / i-hate-regex Goto Github PK

View Code? Open in Web Editor NEW
4.4K 50.0 313.0 7.64 MB

The code for iHateregex.io ๐Ÿ˜ˆ - The Regex Cheat Sheet

Home Page: https://iHateRegex.io

Vue 87.48% JavaScript 7.98% Dockerfile 0.25% Shell 0.04% SCSS 4.26%
regex nuxt vue tailwindcss

i-hate-regex's Introduction

iHateRegex ๐Ÿ˜ˆ

PRs Welcome Nodejs CI

don't just use; understand.

iHateRegex.io - a regex cheatsheet for the haters.

Chat with us on Telegram

Features ๐Ÿ˜Ž

  • Visual representation of regular expressions
  • Matched strings - the Testing area
  • Embed regular expression visualization on your sites
  • Regex code highlighting and validation
  • Regex description with markdown support
  • Playground page where you can create your own expression and link to it.
  • User login and save regex

Setup ๐Ÿš€

  1. Install yarn

  2. Clone this repo

  3. Install dependencies โš™๏ธ

$ yarn install
  1. Test on localhost ๐Ÿ› 
# serve with hot reload at localhost:3600
$ yarn dev
  1. Build and Start nuxt server ๐Ÿš€
# build for production and launch server
$ yarn build
$ yarn start

This project is built with Nuxt.js ๐Ÿ™Œ

For detailed explanation on how things work, check out Nuxt.js docs.

Contribute Regex ๐Ÿ™

Contribute to this project and make this the largest collection of useful expressions ๐Ÿ˜

You can also submit regex via this google form

To contribute:

  1. Add your regex to /static/regex/data.json
Show sample JSON
{
        "id": "username",
        "title": "username",
        "tagline": "match a username",
        "description": "Alphanumeric string that may include _ and - having a length of 3 to 16 characters.",
        "regex": "^[a-z0-9_-]{3,15}$",
        "flag": "gm",
        "matchText": [
            "lorem",
            "ipsum",
            "gr3at",
            "a",
            "ab",
            "abcd",
            "abcde",
            "john doe",
            "johnny",
            "abcdefghijklmnopqrst"
        ],
        "cheatRegex": [
            "/^/",
            "/$/",
            "/[a-zA-Z0-9]/",
            "/(hello){1,3}/"
        ],
        "embedHeight": 300,
        "tags" : ["name", "slug"]
    },
Show JSON properties
Property Definition
id this is the slug and also the short name of the regex. cannot contain spaces and only contain url-safe characters
title Title of the page.
tagline Tagline
description First line under the tagline and also the meta description
regex The actual regex string
flag regex flags associated with the expression. eg; g
matchText Array(line by line) of strings to be included in the string matching are
cheatRegex refer static/regex/cheatsheet.json and see what all cheats are relevent to this expression. (you can also add your own cheats into cheatsheet.json and refer to that)
embedHeight Height in pixels of the regex visualization embed
tags tags related to the expression (to be used later)
  1. Create a markdown file in /static/regex/markdown/ named <regex-id>.md for longer description and explanation

    <regex-id> is the id from data.json

That's it ๐Ÿ™Œ Go ahead and shoot a new pull requestโœจโœจ

Descriptions

There are 2 descriptions for each regex.

  • One is the description property inside /static/regex/data.json.

    • This is used for page meta description as well.
    • This is the first description
  • Second is a dedicated markdown file in /static/regex/markdown/<file>.md

    • This should explain how the expression works in detail.
    • This is the long description
Property Definition example
description property inside data.json This should explain about what the target match is in a few lines. It should not contain any html or markdown A username is a unique identifier given to accounts in websites and social media
dedicated markdown file Explain about the expression and how it works ip addresses are of the range 0.0.0.0 - 255.255.255.255. The expression matches the ....(more)

Sponsors ๐Ÿ’–

Donate via Opencollective

Credits

  • The visual demo is built with: regexper

i-hate-regex's People

Contributors

alex-hofmann avatar andraantariksa avatar divee789 avatar diya-liza avatar ebolaware avatar eyarz avatar fcmam5 avatar geongeorge avatar huy-ngo avatar jamesgeorge007 avatar jjimenezshaw avatar ldsands avatar oussamabouchikhi avatar pragalbha-patil avatar shimont avatar thejabbu avatar tylerdm avatar w3gaucho avatar yshalsager avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

i-hate-regex's Issues

Embed code

Hello,
I'm working on this repository for adding some regex which I thought may be useful. I followed all the mentioned steps. However I'm not getting proper embed turing machine flow.
For my regex it is showing invalid embed image. You can see it here.
Is there anything I'm doing wrong?
Thank you

Question about "lookahead" and "reflash".

I find two small questions about this. As follows:

  1. About "lookahead", I find it can't lookahead forward. For example,
    | play around with regex | matches | expect output | real output |
    | ---------------------- | ---- | ---- | ---- |
    | (?<=num)\d+ | num123 | 123 | Error: Line 1: expected "?"(?<=num)\d+|
  2. When I input regex, it will reflash. But it will set the pointer to the start which makes trouble to input new word and then throws error.

Nonetheless, I absolutely love this util. It offers many samples and can display how the regex matching. Thank you for create this!
XD.

Markdown for "firstdescr"

I believe that we need to reference some resources or RFCs in some regex descriptions, is it possible to support markdown at least only for this field?

Regex for email complicated does not handle curly quotes

The regex (([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})) won't handle emails like

I propose changing it to (([^<>()\[\]\\.,;:\s@"โ€œโ€โ€˜โ€™]+(\.[^<>()\[\]\\.,;:\s@"โ€œโ€โ€˜โ€™]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))

See here for examples

Add user login

Implement user login and allow users to create their own regex pastes
similar to codepen and jsfiddle

Parsing escaped regexes

This is absolutely brilliant!

It would be lovely if I could paste (or type) in a regex that has been written with escapes (e.g. as per a shell script) and for the parser to understand the escapes. As an example...

\(x86\(_64\)\?\|arm\(hf\|v7\)\)\

is the escaped version of

(x86(_64)?|arm(hf|v7))

and to be able to escape or un-escape an expression. That would be fantastic.

Really good tool, just a suggestion. Many thanks for providing ๐Ÿฅ‡

Is there a bug in the online CheatSheet?

Hello I.H.R. DreamTeam,

First congrats for this useful tool, and thanks for your work.

This cheat sheet ( https://ihateregex.io/cheatsheet ) says :
/h.llo/ the '.' matches any one character other than a new line character... matches 'hello', 'hallo' but not 'h llo'

I am afraid I disagree : The last target "h" SPACE "llo" is matched by "/h.llo/", don't you think?
You may have wanted to write "hllo", isn't it?

KUTGW & best regards.

Image match regex

A simple image regex, something like /.*\.(gif|jpe?g|bmp|png)$/igm ๐Ÿ˜„

[Regex issue] URL regex doesn't match all domains

Maximum of 6 characters for TLD is not enough. There are TLDs like .accountants. Currently the longest TLD is 24 characters long, and the limit is 63 characters. So... We have to do something with it. Manually update the length (though it isn't going to change often) or just use 63 characters.
Screenshot

Use I hate regex to document code

I hate regex too and would rather not use it but my coworker do and it makes code review very hard.

I wonder if there could be a simple way to use your awesome service to improve code review.

My first idea was to document code with a link to your service identifying uniquely the regex in the code.

What do you think about it?

State the engine / flavour

I really like the design of your website.
But it nowhere mentions the used engine/flavour (Python2, Python3, JavaScript, ...). There are differences you might know.

Is there a mispelled sentence the Cheat Sheet?

Hello again,

I was reading this :

/h.*llo/ the "STAR" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"

A) This sems to be false : The STAR characters does not match any character. It is a special character for multi-items pattern.

  • a REGEX-PATTERN followed by a STAR means "0 or more" of the preceding PATTERN.
  • Additional parameters may specify : "more" means "as many as possible" (this is a "greedy" behavior) or "as little as possible" (this is "non-greedy" behavior).

So, you might have wanted to write : ".*"
"The POINT followed by a STAR matches any character...etc."

B) After "any character" you forgot to specify + "other than a new line character." as you did in previous comment, so in order to have consistent explanations, would it be better to add it?

-- KUTGW & best regards

'username' regex doesn't match description

The regex for matching usernames doesn't match the given description.

Given description:

Alphanumeric string that may include _ and - having a length of 3 to 16 characters.
A username must not contain 2 underscores or 2 hyphens in a row. Also, it cannot have an
underscore, hyphen or a space at the start.

But it still matches strings like:

  • -ab
  • a--b
  • a__

Fix:
Either change the description or the regex.

Here's a regex that follows the description except the minimum and maximum amount of characters allowed. /^[a-zA-Z0-9]+([_-]?[a-zA-Z0-9])*$/

issue with regex for ip address(ipv4)

I came across a small issue with the regex matching for ipv4, it's supposed to check that the ip address is in the range of 0.0.0.0 to 255.255.255.255 but this can fail when you get a number where just the first octet is larger then 255.
For example the ip address 341.25.015.22 passes because the starting 3 is ignored, then it appears valid.
Currently the regex for ipv4 is (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}
But I believe it should be (\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}
to include cases where the initial number may be out of range, but in range if you ignore the first character. The match should begin at the start of the word. Test cases that would be incorrect before, but are resolved by the suggestion below.
341.25.015.22
4248.254.1.1
972.52.4.12
1255.34.22.58

Support named captures

It would be great have named captures support, ie:

^A bell-like tone rings out from (?\w+)'s rapier, echoed by the sound of cracking bone as your (?:left|right) (?:arm|leg) snaps painfully.$

Domain match regex

It will match Domain name.

Regex:

(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]

Example:

test.com - valid
test--.main.com - invalid

(feature request) Dark theme

Thank you for the great work!
The site visualizes even very complex regexes with ease!! Love it!

I'd like to make just a suggestion, please: an optional dark theme.
I personally find them much easier on the eyes.

Thank you!

Matcher on website doesn't show matches correctly on e.g. IPv6

Hi,

The following IPs do match the given regexp if used in grep(1) but not entirely on the website. I use bold (double star) in this issue to show which part were highlighted.

"regex": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))",

Those should completely match:

  • **2001:db8::**1
  • **123::**456:789
  • FE80:0000:0000:0000:0202:B3FF:FE1E:8329%eth0
  • **fe80::**aaaa:bbbb:eeee:1111%eth0

Regex for matching b64 encoded IP

This will match valid IPs from 0.0.0.0 to 255.255.255.255 which are base64 encoded.

let regex = /[MNO][CDSTijyz][4AEIMQUYcgk][012345uwxyz][LMNO][CDSTijyz][4AEIMQUYcgk][012345uwxyz][LMNO][ACDQSTgijwyz]([4=AEIMQUYcgk]{1}([012345=uwxyz]{1}([LMNO]{1}([ACDQSTgijwyz]{1}([4=AEIMQUYcgk]{1}([012345=uwxyz]{1}([MNO]{1}([ADQTgjwz]{1}([=AEIMQUYcgk]{1}([012345=wxyz]{1})?)?)?)?)?)?)?)?)?)?/gm;

The following IPs will match:

let matching_ips = [
  "MjU1LjI1NS4yNTUuMjU1",   // 255.255.255.255
  "MTIuMTIzLjE0Mi4xMjM=",   // 12.123.142.123
  "MjU1LjI1NS4yNTUuMg==",   // 255.255.255.2
  "MjU1LjIuMjUuMjU1",   // 255.2.25.255
  "MTIzLjEuMi4xMjM=",   // 123.1.2.123
  "NzguNTYuNDUuMg==",   // 78.56.45.2
  "MTIuNDUuMi4x",   // 12.45.2.1
  "OTEuMS4xLjE=",   // 91.1.1.1
  "MS4yLjMuNA==",   // 1.2.3.4
  โ€ฆ // and so on
]

The following won't:

let non_matching_ips = [
  "LTEuMi4zLjQ", // -1.2.3.4
  "MS4y", // 1.2,
  โ€ฆ // and so on
]

Unfortunately, there are some false-positives, as it matches for example 255.255.255.256, 256.256.256.256 and 1.02.3.4, which cannot be eradicated without massive efforts and making the expression even more unreadable.
But for extracting encoded IPs from some data to use it, for example as an IOC, this might be enough, and it's feasible to expect from a human being to check if an IP is valid.

Installing attempt failed on test "yarn dev"

I'm noob in yarn so sorry
Please help as there's step in failure:

$ yarn dev

 WARN  [email protected] is installed but ^10.1.1 is expected                                  03:04:07


 WARN  mode option is deprecated. You can safely remove it from nuxt.config                    03:04:10

โ„น Using Tailwind CSS from ~/assets/styles/tailwind.scss                       nuxt:tailwindcss 03:04:10

 FATAL  Your application tried to access tailwindcss, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: tailwindcss (via "tailwindcss/defaultTheme")
Required by: /home/budi/Downloads/i-hate-regex/assets/styles/

Require stack:
- /home/budi/Downloads/i-hate-regex/assets/styles/tailwind.config.js

  
  Required package: tailwindcss (via "tailwindcss/defaultTheme")
  Required by: assets/styles/
  
  Require stack:
  - assets/styles/tailwind.config.js
  at require$$0.Module._resolveFilename (.pnp.cjs:26511:13)
  at Function.resolve (node:internal/modules/cjs/helpers:109:19)
  at _resolve (.yarn/cache/jiti-npm-1.16.0-a3cbfd13e3-28844cd691.zip/node_modules/jiti/dist/jiti.js:1:243302)
  at jiti (.yarn/cache/jiti-npm-1.16.0-a3cbfd13e3-28844cd691.zip/node_modules/jiti/dist/jiti.js:1:245428)
  at assets/styles/tailwind.config.js:1:95
  at Resolver.jiti [as _require] (.yarn/cache/jiti-npm-1.16.0-a3cbfd13e3-28844cd691.zip/node_modules/jiti/dist/jiti.js:1:247502)
  at Resolver.requireModule (.yarn/cache/@nuxt-core-npm-2.15.8-ea349e16fd-413e907a50.zip/node_modules/@nuxt/core/dist/core.js:381:29)
  at module.exports (.yarn/cache/@nuxtjs-tailwindcss-npm-3.4.3-4f2ebbe345-b9a2802f97.zip/node_modules/@nuxtjs/tailwindcss/lib/module.js:36:36)
  at async ModuleContainer.addModule (.yarn/cache/@nuxt-core-npm-2.15.8-ea349e16fd-413e907a50.zip/node_modules/@nuxt/core/dist/core.js:239:20)
  at async ModuleContainer.ready (.yarn/cache/@nuxt-core-npm-2.15.8-ea349e16fd-413e907a50.zip/node_modules/@nuxt/core/dist/core.js:51:7)
  at async Nuxt._init (.yarn/cache/@nuxt-core-npm-2.15.8-ea349e16fd-413e907a50.zip/node_modules/@nuxt/core/dist/core.js:478:5)

How to solve out ?

Search: Pressing 'enter' returns a 404

When using the search box, the search returns results correctly automatically. However, when you press the enter key, this returns a 404:

It doesn't seem to matter what the search is.

No license

It seems that you would want others to use and contribute to this software. It would be good to have a license (even just MIT/ISC) so people can use and modify it legally. However, I would recommend AGPLv3 since I think what you are doing is particularly important.

Retain the cursor position after highlighting

Feature Request

The cursor inside the matches box jumps to the initial position after a person edits and highlighting is performed.
I was not able to find a proper method to get the cursor location inside a div and place the cursor at that position after I add the highlighting HTML.

This also makes it so that we cannot perform real-time highlighting. I've set a timeout:
components/post-components/MatchBox.vue

matchboxChanged(event) {
      var node = this.$refs.matchbox;
      // console.log(typeTimeout);
      if (typeTimeout) {
        clearTimeout(typeTimeout);
      }
      typeTimeout = setTimeout(() => {
        this.boxEdited();
      }, 2000);
    }

Add an "All Regex" page

There is no sitemap nor a page where all expressions are visible.

Desired result:
/expr/ should show all available expressions

Support for VerbalExpressions?

Hi,

The diagram rendering of a regexp is very nice and helpful.

Any chance adding support for Verbal Expressions? https://github.com/VerbalExpressions -> they seem to map in "words" very nicely the diagram blocks.

So the idea would be for a regexp like /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
to also generate besides the diagram the VerbalExpression text alternative:

const tester = VerEx()
    .startOfLine()
    .then('http')
    .maybe('s')
    .then('://')
    .maybe('www.')
    .anythingBut(' ')
    .endOfLine();

for the desired programming language.

See https://github.com/VerbalExpressions/JSVerbalExpressions#testing-if-we-have-a-valid-url

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.