Find me on twitter @geongeorgek
geongeorge / i-hate-regex Goto Github PK
View Code? Open in Web Editor NEWThe code for iHateregex.io 😈 - The Regex Cheat Sheet
Home Page: https://iHateRegex.io
The code for iHateregex.io 😈 - The Regex Cheat Sheet
Home Page: https://iHateRegex.io
Find me on twitter @geongeorgek
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.
Hello,
https://ihateregex.io/expr/date/
The date regex gets leap years wrong. Leap years divisible by 400 should not match.
The regex successfully matches Feb 29, 2000. It should not.
BTW, other than leap year it is an amazing regex, thank you.
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
Request for ISO 8601 (date & time format) Regex.
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.$
There is no sitemap nor a page where all expressions are visible.
Desired result:
/expr/
should show all available expressions
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 ?
It would be cool if matching valid CIDR address notation was also supported.
It's common in IT fields to match on what network an IP address is part of.
Route tables are my main use case.
https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
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.
A simple image regex, something like /.*\.(gif|jpe?g|bmp|png)$/igm
😄
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);
}
I find two small questions about this. As follows:
Nonetheless, I absolutely love this util. It offers many samples and can display how the regex matching. Thank you for create this!
XD.
样例:** 哈尔滨市电话号码:0451-57578888
该规则的电话号码在**很常见:[四位区号]-[八位号码]
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
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?
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.
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!
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?
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.
Add regex to match numbers with comma for thousands and dot for decimals:
1,999,999.88
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.
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
I tried ^foo$
but it wont work.
foo$ works
and ^foo
As a contributor, I want to validate my recently added Regex
escape user input tags in matchbox
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
“[email protected]”
(curly quote)'[email protected]'
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 more info. Basically using \p{Letter}
(or the shortened \p{L}
) matches any unicode character that is a letter. This way you match things like ñ
.
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
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.
i-hate-regex/static/regexdata.json
Line 176 in dc4299e
Those should completely match:
CPF regex not found
This website is very very helpful for me.
And, Everyone rejoices if multi-language supported!
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])*$/
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.
https://ihateregex.io/expr/email/
The subdomain email is ok.
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 🥇
Regular Expression engines differ from one language to another:
https://en.wikipedia.org/wiki/Comparison_of_regular-expression_engines
What would it mean to allow plugging-in different engine, as in: https://regex101.com/
Is there any work being done on that front ?
By comments I mean comments in code, such as
// single line comment
/** multi
* line
* comment
*/
for some reason my browsers crash every time I access this link https://ihateregex.io/expr/url
somebody else?
details:
Its really hard to navigate horizontally when the regex graph is really big. One have to scroll down to be able to use horizontal scroll.
Implement user login and allow users to create their own regex pastes
similar to codepen and jsfiddle
I'm not convinced the \b
in the UUID regex serve any purpose. Why are we trying to match word boundaries here?
^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$
(I tested the regex without the \b
and the same strings match or don't match)
@alex-hofmann do you remember why you added those?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.